【问题标题】:Will componentDidUpdate fire everytime for a component that renders null?每次呈现 null 的组件都会触发 componentDidUpdate 吗?
【发布时间】:2019-05-01 08:07:28
【问题描述】:

componentDidUpdate 是否总是会为呈现空片段/null 的组件触发?它从父容器接收 redux 连接的 props。

该组件需要访问之前的 props 并进行比较,然后基于它进行 API 调用。它没有 UI,所以它呈现空片段(或 null)

EDIT :它正在我的示例应用程序中工作并触发 componentDidUpdate。这是否保证始终是这种行为? 它在这里说,当虚拟 DOM 没有变化时,它可能不会触发:Props updated, componentDidUpdate did not fire

MyContainer
 |
  -MyComponent

【问题讨论】:

标签: reactjs react-redux


【解决方案1】:

是的,它每次都运行,而不是在第一次初始渲染时运行

【讨论】:

    【解决方案2】:

    是的,每次都会调用 componentDidUpdate,即使在呈现 null 时也是如此。你可以在 react 文档中查看:React Lifecycle

    【讨论】:

    猜你喜欢
    • 2017-02-13
    • 2016-06-29
    • 1970-01-01
    • 2020-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-30
    相关资源
    最近更新 更多