Created
November 5, 2016 22:52
-
-
Save bwll/065564962adc43fd64818c2c579abfef to your computer and use it in GitHub Desktop.
Counter Component in React
This file contains 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
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