小编bit*_*gmi的帖子

What is the advantage of using componentDidUpdate over the setState callback?

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 …

javascript setstate reactjs

5
推荐指数
1
解决办法
253
查看次数

标签 统计

javascript ×1

reactjs ×1

setstate ×1