Created
June 23, 2016 18:34
-
-
Save bryceosterhaus/3102b0136b2309c5c8a7bf55531f3d03 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Component from 'metal-jsx'; | |
| class Child extends Component { | |
| created() { | |
| this.incrementCount = this.incrementCount.bind(this); | |
| this.handleClick = this.handleClick.bind(this); | |
| } | |
| handleClick() { | |
| setTimeout(this.incrementCount, 0); | |
| setTimeout(this.incrementCount, 0); | |
| } | |
| incrementCount() { | |
| const {count} = this; | |
| this.onChange(count + 1); | |
| } | |
| render() { | |
| return ( | |
| <div> | |
| <button onClick={this.handleClick}>Click Me</button> | |
| {this.count} | |
| </div> | |
| ); | |
| } | |
| } | |
| Child.STATE = { | |
| count: {}, | |
| onChange: {} | |
| } | |
| class Parent extends Component { | |
| created() { | |
| this.handleChange = this.handleChange.bind(this); | |
| } | |
| handleChange(value) { | |
| this.count = value; | |
| } | |
| render() { | |
| return ( | |
| <div> | |
| <Child count={this.count} onChange={this.handleChange} /> | |
| </div> | |
| ); | |
| } | |
| } | |
| Parent.STATE = { | |
| count: { | |
| value: 0 | |
| } | |
| } | |
| export default Parent; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment