本文介绍了道具已更新,componentDidUpdate未触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否曾经有一种情况,即使在React中更新了props,componentDidUpdate也不会触发?

Is there ever a situation where componentDidUpdate would NOT fire, even if the props updated in React?

推荐答案

有3种情况可能导致componentDidUpdate无法启动:

There are 3 conditions that can cause componentDidUpdate to not fire:

1)您编写了一个返回false的自定义shouldComponentUpdate.

1) You wrote a custom shouldComponentUpdate that returned false.

2)内部react方法确定虚拟DOM中没有变化,因此选择不重新渲染.

2) The internal react methods determined that there was no change in the virtual DOM, so it chose not to re-render.

3)您扩展了React.Component之外的其他内容(例如PureComponent),该扩展具有默认的shouldComponentUpdate方法,该方法返回false.

3) You extended something other than React.Component (such as PureComponent) which has a default shouldComponentUpdate method that returned false.

这篇关于道具已更新,componentDidUpdate未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 21:20