react生命周期的四个阶段
组件初始化阶段:
getInitialState:初始化 this.state 的值,只在组件装载之前调用一次
getDefaultProps:只在组件创建时调用一次并缓存返回的对象(即在 React.createClass 之后就会调用)。
因为这个方法在实例初始化之前调用,所以在这个方法里面不能依赖 this 获取到这个组件的实例。
组件加载阶段:
componentWillMount:只会在装载之前调用一次
componentDidMount:只会在装载完成之后调用一次
组件更新阶段:
componentWillReceiveProps 、shouldComponentUpdate、componentWillUpdate、componentDidUpdate这些方法不会在首次render组件的 周期调用。
组件销毁阶段:
componentWillUnmount:卸载组件触发
08-30
116
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)