生命周期

React < v16.3

图:React < v16.3 生命周期图

  • 红色是在 v17 版本后废弃的生命周期。

  • 细字体的声明周期是不常用的,加粗是常用的。

React > v16.3

React v16.3,引入了两个新的生命周期函数:

  • getDerivedStateFromProps

  • getSnapshotBeforeUpdate

TipsgetDerivedStateFromProps 实际上就是用来取代以前的 componentWillMountcomponentWillReceiveProps

随着 getDerivedStateFromProps 的推出,同时deprecate了一组生命周期API,包括:

  • componentWillReceiveProps

  • componentWillMount

  • componentWillUpdate

新的生命周期图如下图所示:

图:React > v16.3 生命周期图
  • 细字体的声明周期是不常用的,加粗是常用的。

Last updated