[React] React components in ES6 classes

class App extends React.Component{
  constructor(){
    super();
    this.state = {
      count: 0
    }
  }
  increaseCount(){
    this.setState({count: this.state.count +1});
  }
  render(){
    return (
      <button onClick={this.increaseCount.bind(this)}>{this.props.txt} - {this.state.count}</button>
    )
  }
}

App.defaultProps = {
  txt: "Click to increase!"
};
App.propTypes = {
  txt: React.PropTypes.string.isRequired
}

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

 

posted @ 2015-08-10 20:53  Zhentiw  阅读(383)  评论(0)    收藏  举报