The meaning of life is to explore the world

React state life cycle

Posted on By Jason Liu

React state life cycle
See the link from offical webiste:
https://projects.wojtekmaj.pl/react-lifecycle-methods-diagram/

my_image

Update the state from props:
Sometimes we need to update the state from props, as constructor will only be called once regardless of props change from parent.
We can do that in getDerivedStateFromProps() or componentDidUpdate().
The getDerivedStateFromProps() is static and it may not work before rendering.
The componentDidUpdate() may trigger another rendering and even dead loop.