简体   繁体   中英

Does this.forceUpdate rerender all children?

The documents have the following to say about forceUpdate:

Calling forceUpdate() will cause render() to be called on the component, skipping shouldComponentUpdate(). This will trigger the normal lifecycle methods for child components, including the shouldComponentUpdate() method of each child. React will still only update the DOM if the markup changes.

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

Does this mean that children of the component also have their render function called?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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