Why does the official Doc recommend using componentDidMount instead of callback in setState?

https://facebook.imtqy.com/react/docs/react-component.html#setstate

It seems to me that the official document says:

The second parameter to setState () is an optional callback function that will be executed after setState completes and the component is rendered again. We usually recommend using componentDidUpdate () for this logic.

why do they recommend using componentDidUpdate instead of a callback when we need to use the last state?

+4
source share
1 answer

componentDidUpdatealso called immediately after each update. The latest status is currently being updated.

componentDidUpdate , callback setState.

, redux, setState . redux

: componentDidUpdate .

https://facebook.imtqy.com/react/docs/react-component.html#componentdidupdate

0

Source: https://habr.com/ru/post/1683327/


All Articles