简体   繁体   English

this.forceUpdate是否会重新呈现所有子级?

[英]Does this.forceUpdate rerender all children?

The documents have the following to say about forceUpdate: 这些文档对forceUpdate有以下说法:

Calling forceUpdate() will cause render() to be called on the component, skipping shouldComponentUpdate(). 调用forceUpdate()将导致在组件上调用render(),而跳过shouldComponentUpdate()。 This will trigger the normal lifecycle methods for child components, including the shouldComponentUpdate() method of each child. 这将触发子组件的正常生命周期方法,包括每个子组件的shouldComponentUpdate()方法。 React will still only update the DOM if the markup changes. 如果标记发生更改,React仍然只会更新DOM。

https://reactjs.org/docs/react-component.html#forceupdate https://reactjs.org/docs/react-component.html#forceupdate

Does this mean that children of the component also have their render function called? 这是否意味着该组件的子代也调用了其render函数?

It will "re-render" every child that does not return false inside of its shouldComponentUpdate method, however note that re-rendering !== re-drawing , it will just cause React's diffing algorithm to run. 它将“重新渲染”在其shouldComponentUpdate方法内部未返回false的每个子代,但是请注意, re-rendering !== re-drawing ,只会导致React的差异算法运行。

And only, if the diffing algorithm sees a difference in the current version of the virtual DOM compared to the previous version of the virtual DOM will the specific "changed" part of the UI get re-drawn on the screen. 而且,如果差异算法发现虚拟DOM的当前版本与虚拟DOM的先前版本相比有所不同,则UI的特定“更改”部分将重新显示在屏幕上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM