总结了react生命周期
一共十个钩子(只有在类组件里面才能定义生命周期钩子)
一、Initalization
1、set up props and state(初始化的时候只执行一次)
二、Mounting(下面三个挂载的时候只执行一次)
1、componentWillMount(组件还没有mount之前,类似于vue的beforeMount)
2、render(是一个钩子,表示去渲染一个view)
3、componentDidMount(表示当前的dom渲染完毕了或者mounted结束了,会触发这个)
三、Updation(更新的时候两个地方组件更新)
1、props (父组件属性传过来的时候会触发5个钩子)
1)componentWillReceiveProps(将要收到父组件传过来的属性)
2)shouldComponentUpdate(真的要更新我们的组件吗?true就走到componentWillUpUpdate,false就中断了)
3)componentWillUpUpdate()
4)render()
5)componentDidUpdate()
2、states(组件内部的组件修改也会触发后四个钩子,因为状态的修改不涉及到props的更新)
1)shouldComponentUpdate(真的要更新我们的组件吗?true就走到componentWillUpUpdate,false就中断了)
2)componentWillUpUpdate()
3)render()
4)componentDidUpdate()
四、Unmounting
componentWillUnmount(组件被卸载之前触发的)