react组件自定义写法

var LikeButton = React.createClass({
  getInitialState: function() {
    return {liked: false};
  },
  handleClick: function(event) {
    this.setState({liked: !this.state.liked});
  },
  render: function() {
    var text = this.state.liked ? '喜欢' : '不喜欢';
    return (
     


        你{text}我。点我切换状态。
     


    );
  }
});


React.render(
  ,
  document.getElementById('example')
);

你可能感兴趣的:(react)