ReactJS:componentDidUpdate和setState的第二个参数有什么区别? [英] ReactJS: What is the difference between componentDidUpdate and the second parameter of setState?
本文介绍了ReactJS:componentDidUpdate和setState的第二个参数有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这两个功能之间有什么区别吗? (除了他们的论点) 那些方法似乎具有相同的触发器,不是吗?
Is there any difference between those 2 functions? (besides their arguments) It seems like those methods have the same triggers, isn't it?
感谢您的帮助:)
推荐答案
componentDidUpdate
,这可能是由于以下原因之一引起的:
componentDidUpdate
is called whenever the component has re-rendered, which might be caused by either:
- 状态改变
- 对
forceUpdate
的调用
- 父组件重新呈现(如果是顶级组件,则重新调用
React.render
)
- a change in state
- a call to
forceUpdate
- a parent component re-rendering (or another call to
React.render
in the case of the top-level component)
setState
回调仅在状态转换完成且组件已重新呈现后才被调用.
The setState
callback will only be called once the state transition has completed and the component has re-rendered.
这篇关于ReactJS:componentDidUpdate和setState的第二个参数有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文