React类组件中生命周期函数执行顺序

一、组件生命周期的执行次数是什么样子的?


image.png

二、组件的生命周期执行顺序是什么样子的?
假设组件嵌套关系是 App里有parent组件,parent组件有child组件。


image

如果不涉及到setState更新,第一次渲染的顺序如下:

image

image.png

这时候触发App的setState事件

image

image.png

那如果是触发parent的setState呢?

image
parent: componentWillUpdate --> render --> 
child:     componentWillReceiveProps --> componentWillUpdate --> render --> 
componentDidUpdate (child) -->  componentDidUpdate (parent) 

那如果是只是触发了child组件自身的setState呢?

image

image.png

文章内容转载于https://www.cnblogs.com/faith3/p/9216165.html

你可能感兴趣的:(React类组件中生命周期函数执行顺序)