首页 > 解决方案 > 当且仅当调用render时才调用componentDidUpdate?

问题描述

React 组件有一个render方法,也可以有一个componentDidUpdate方法。我的问题是:每次componentDidUpdate渲染后都会被调用,是否有任何时候被调用但不是?componentDidUpdaterender

标签: reactjs

解决方案


componentDidUpdate总是在 之后调用render。因此,如果您阻止渲染,shouldComponentUpdate例如,didUpdate将永远不会被调用

是否有任何时候 componentDidUpdate 被调用但 render 不是?

不,componentDidUpdate取决于render被调用。但是相反的情况可能会发生,componentDidUpdate 在第一次渲染后不会被调用


推荐阅读