【转】React组件声明周期
转自大神。。备份一下~
参考链接 http://reactjs.cn/react/docs/component-specs.html
组件
render : function(){}
必须方法。
返回null
或false
表示不渲染任何东西。getInitialState : function(){}
返回值将作为this.state
的初始值getDefaultProps : function(){}
返回值将作为默认的props。propTypes : {}
props数据约束statics : {}
定义该组件对象的静态方法
生命周期(按照调用顺序)
componentWillMount : function(){}
在初始化渲染之前仅调用一次componentDidMount : function(){}
在初始化渲染之后仅调用一次componentWillUpdate : function(props,state){}
在接收新的props
和state
之前调用。componentWillReceiveProps : function(props){}
在接收新的props的时候调用。shouldComponentUpdate : function(props,state){}
在渲染之前调用。返回值为false
则表示组件不更新。componentDidUpdate : function(props,state){}
在组件同步到DOM中后调用componentWillUnmount : function(){}
在组件移除DOM时调用