Why is using componentDidUpdate
more recommended over the setState
callback function (optional second argument) in React components (if synchronous setState behavior is desired)?
Since setState
is asynchronous, I was thinking about using the setState
callback function (2nd argument) to ensure that code is executed after state has been updated, similar to then()
for promises. Especially if I need a re-render in between subsequent setState
calls.
However, the official React Docs say "The second parameter to setState() is an optional callback …