React生命周期(新版)

190 阅读1分钟

React生命周期(新版)

8cf4d1f413e676f4129a3feacd8a29f.png

挂载阶段

constructor ==> 初始化

static getDerivedStateFromProps ==> 判断前后的值

render ==> 组件渲染

componentDidMount ==> 组件挂载后执行(浏览器之前)

更新阶段

static getDerivedStateFromProps ==> 判断前后的值(属性改变)

shouldComponentUpdate ==> 是否要更新

render ==> 重新渲染

getSnapshotBeforeUpdate ==> 获取快照

componentDidUpdate ==> 更新后执行

卸载阶段

componentWillUnmount ==> 组件卸载前执行

错误处理阶段

componentDidCatch ==> 发生错误后执行