Skip to content

Instantly share code, notes, and snippets.

@osmelmora
Created Jul 14, 2016
Embed
What would you like to do?
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