组件在创建到死亡他会经历一系列的特殊阶段,组件中包含一系列钩子函数,会在特定的时间调用
一、componentWillMount 组件挂载之前调用
二、componentDidMount组件挂载完毕调用======>常用,一般在这做初始化的事(开启定时器,发送网络请求,订阅消息)
三、componentWillUnmount组件卸载之前调用=====>常用,一般做一些收尾的事情(关闭定时器,取消订阅消息)
卸载组件unmountComponentAtnode(document.getElementById('id'))
四、shouldComponentUpdate 控制组件更新的阀门,返回ture更新,返回false不更新,必须返回true或者false
五、componentWillUpdate 组件将要更新
六、componentDidUpdate 组件更新
七、componentWillReceiveProps 父组件将要更新传给子组件的props
八、调用顺序
挂载:componentWillMount =>render=>componentDidMount=>componentWillUnmount
调用setState函数:shounldComponentUpdate=>componentwillUpdate=>render=>componentDidUpdate=>componentWillUnmount
this.forceUpdate():componentwillUpdate=>render=>componentDidUpdate=>componentWillUnmount
父组件更新子组件props:componentWillReceiveProps=>shounldComponentUpdate=>componentwillUpdate=>render=>componentDidUpdate=>componentWillUnmount