生命周期图
一、挂载
1.construct
构造函数
2.static getDerivedStateFromProps(props, state)
监听props更新state
需要返回状态或对象
return null
3.render
渲染
4.componentDidMount
组件已经挂载
二、更新
1.static getDerivedStateFromProps(props, state)
监听props更新state
2.shouldComponentUpdate(nextProps,nextState){}
组件是否更新
3.render
4.getSnapshotBeforeUpdate()
在更新之前获取快照
需要返回一个值
返回的值传递给componentDidUpdate
5.componentDidUpdate(preProps, preState, snap){}
组件已经更新
三、卸载
1.componentWillUnmount
组件将要卸载