> For the complete documentation index, see [llms.txt](https://cosmos-x.gitbook.io/react-development-guides/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cosmos-x.gitbook.io/react-development-guides/2.-react-ji-chu/sheng-ming-zhou-qi.md).

# 生命周期

## React < v16.3

![图：React < v16.3 生命周期图](/files/-LrtIeUlIoPFy_I0288A)

* 红色是在 v17 版本后废弃的生命周期。
* 细字体的声明周期是不常用的，加粗是常用的。

## React > v16.3

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

* **getDerivedStateFromProps**
* **getSnapshotBeforeUpdate**

{% hint style="info" %}
**Tips**：`getDerivedStateFromProps` 实际上就是用来取代以前的 `componentWillMount` 和 `componentWillReceiveProps`
{% endhint %}

随着 `getDerivedStateFromProps` 的推出，同时deprecate了一组生命周期API，包括：

* **componentWillReceiveProps**
* **componentWillMount**
* **componentWillUpdate**

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

![图：React > v16.3 生命周期图](/files/-LrtJLH1xEOitqfhneyD)

* 细字体的声明周期是不常用的，加粗是常用的。
