gpt4 book ai didi

javascript - React componentWillUpdate 被调用两次

转载 作者:行者123 更新时间:2023-12-01 01:18:08 24 4
gpt4 key购买 nike

我是 React 新手,我遇到了这个 doc 。它说:

Either way, it is unsafe to use componentWillUpdate for this purpose in async mode, because the external callback might get called multiple times for a single update

componentWillUpdate怎么可能被多次调用呢?它没有解释它。

谢谢

最佳答案

任何应该触发渲染的更改都将首先经历 componentWillUpdate 生命周期。更改可以是父级重新渲染导致子级重新渲染、组件 props 的更改或状态的更改。

但是从 v16.3.0 开始,此生命周期方法已被弃用,并且鼓励在 componentDidUpdate 中处理任何副作用,该副作用将在 render 方法后触发。

关于javascript - React componentWillUpdate 被调用两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54533907/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com