Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var Counter = React.createClass({
- incrementCount: function(){
- this.setState({
- count: this.state.count + 1
- });
- },
- decrementCount: function(){
- if (this.state.count > 0) {
- this.setState({
- count: this.state.count - 1
- });
- }
- },
- getInitialState: function(){
- return {
- count: 0
- }
- },
- render: function(){
- return (
- <div class="counter">
- <h1>Count: {this.state.count}</h1>
- <button type="button" onClick={this.incrementCount}>Increment</button>
- <button type="button" onClick={this.decrementCount}>Decrement</button>
- </div>
- );
- }
- });
- React.render(<Counter/>, document.getElementById('box'));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement