1 初始化:
constructor(): 与React.Component一起使用,ES6
constructor(props) { // 初始化的工作放入到构造函数
super(props); // 在 es6 中如果有父类,必须有 super 的调用用以初始化父类信息
this.state = { // 初始 state 设置方式
};
}
getDefaultProps():设置默认props,如果父组件没有给某个prop那就用默认的,
getInitialState():与React.createClass一起使用,ES5,是设置组件mount以后的初始state的。
getInitialState:function(){
return {};
}
2更新:
componentWillMount(): 在组件 render
之前执行且永远只执行一次
componentDidMount():组件加载完毕之后立即执行,并且此时才在 DOM 树中生成了对应的节点,因此我们通过 this.getDOMNode() 来获取到对应的节点。
componentWillReceiveProps()
3渲染:
componentWillUpdate()
render()
componentDidUpdate()
4销毁:
componentWillUnmount()