Skip to content

Instantly share code, notes, and snippets.

@osmelmora
Created July 14, 2016 18:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save osmelmora/d8c66cbb19b01e431e429849e43c70ba to your computer and use it in GitHub Desktop.
Save osmelmora/d8c66cbb19b01e431e429849e43c70ba to your computer and use it in GitHub Desktop.
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