Created
July 14, 2016 18:47
-
-
Save osmelmora/d8c66cbb19b01e431e429849e43c70ba 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
class Counter extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = {count: 0}; | |
this.incrementCounter = this.updateCounter.bind(this, 1); | |
this.decrementCounter = this.updateCounter.bind(this, -1); | |
} | |
render() { | |
return ( | |
<div> | |
<div>{this.state.count}</div> | |
<input type='button' value='+' onClick={this.incrementCounter} /> | |
<input type='button' value='-' onClick={this.decrementCounter} /> | |
</div> | |
); | |
} | |
updateCounter(count) { | |
this.setState({count: this.state.count + count}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment