简体   繁体   English

在 React 中,如果子组件渲染,父组件是否也渲染?

[英]In React, if a child component renders, does the parent component render too?

In React, if a child component renders, does the parent component render too?在 React 中,如果子组件渲染,父组件是否也渲染? Or only the child component itself get rendered?还是只有子组件本身被渲染?

Short Answer: React doesn't re-render parent if the child component re-renders简短回答:如果子组件重新渲染,React 不会重新渲染父组件

Long Answer The way re-renders and diffing works with react is through a virtual dom and a reconcilation process.长答案re-renders 和 diffing 与 react 一起工作的方式是通过一个虚拟 dom 和一个协调过程。

React creates a tree like structure of your app hierarchy and compares code levelwise React 创建一个树状结构的应用程序层次结构并逐级比较代码

So at any level if there is a change, react triggers render function of all children below it in the hierarchy.因此,在任何级别,如果有变化,反应触发器会渲染层次结构中所有子级的 function。 Obviously triggering render function doesn't mean things change in the dom only changes relevant to elements are being updated in the dom.显然触发渲染 function 并不意味着 dom 中的事情发生变化,只有与元素相关的变化在 dom 中被更新。

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

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