Skip to content

Instantly share code, notes, and snippets.

@bwll
Created November 5, 2016 22:52
Show Gist options
  • Save bwll/065564962adc43fd64818c2c579abfef to your computer and use it in GitHub Desktop.
Save bwll/065564962adc43fd64818c2c579abfef to your computer and use it in GitHub Desktop.
Counter Component in React
var Counter = React.createClass({
getInitialState: function() {
return {
count: 0
}
},
incrementCount: function() {
this.setState({
count: this.state.count + 1
})
},
decrementCount: function() {
this.setState({
count: this.state.count - 1
})
},
render: function() {
return (
<div>
<div>{this.state.count}</div>
<button onClick={this.decrementCount}> - </button>
<button onClick={this.incrementCount}> + </button>
</div>
)
}
});
ReactDOM.render(
<Counter />,
document.getElementById('container')
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment