ReactJS: Counter

This entry is part 18 of 35 in the series React JS

See the Pen React JS counter by daryl (@darylw) on CodePen.0

var Counter = React.createClass({
  incrementCount: function(){
    this.setState({
      count: this.state.count + 1
    });
  },
  decrementCount: function(){
    this.setState({
      count: this.state.count - 1
    });
  },
  getInitialState: function(){
     return {
       count: 0
     }
  },
  render: function(){
    return (
      <div className="counter">
        <h1>{this.state.count}</h1>
        <button className="btn" onClick={this.incrementCount}>Increment</button>
        <button className="btn" onClick={this.decrementCount}>Decrement</button>
      </div>
    );
  }
});

React.render(
<Counter />,
  document.body
);