React在ES6的实现中去掉了getInitialState

1、React在ES6的实现中去掉了getInitialState这个hook函数,规定state在constructor中实现,如下:
  ClassAppextendsReact.Component{
    constructor(props){
      super(props);
      this.state={};
    }
  }

2、Babel的Blog上还有一种实现方法,即直接使用赋值语句:
  ClassAppextendsReact.Component{constructor(props){super(props);}state={}}

posted @ 2017-07-02 16:18  爱美的女孩儿  阅读(2426)  评论(0编辑  收藏  举报