react关于props和state举个例子

var Counter = React.createClass({
  getInitialState: function() {
    return {count: this.props.initialCount};
  },

  handleClick: function() {
    this.setState({count: this.state.count + 1});
  },

  render: function() {
    return <div onClick={this.handleClick}>{this.state.count}</div>;
  }
});

React.render(<Counter initialCount={7}/>, mountNode);
 
posted @ 2016-04-18 12:01  自在灬天  阅读(187)  评论(0编辑  收藏  举报