当且仅当调用render时才调用componentDidUpdate吗?

时间:2019-10-01 13:54:49

标签: reactjs

反应组件具有render方法,并且可以具有componentDidUpdate方法。我的问题是:<{>} 渲染之后是否会调用componentDidUpdate,是否有componentDidUpdate被调用而render没有被调用的情况?

1 个答案:

答案 0 :(得分:2)

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

是否有任何时候调用componentDidUpdate但没有渲染?

否,componentDidUpdate取决于要调用的render。但是相反的情况可能发生,componentDidUpdate doesn't get called after the first render