当儿童组件中发生变化时,父组件会重新呈现吗?
我有一个看起来像这样的父组件:
const Parent = () => {
return (
<Child_1 />
<Child_2 />
);
}
如果一个子组件中发生任何更改,则父组件会重新租赁吗?
I have a parent component which looks like this:
const Parent = () => {
return (
<Child_1 />
<Child_2 />
);
}
if any changes occur in one of the child components, will the Parent component re-renders ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不,它不会重新渲染。如果将任何道具传递给父母组件的组件,并且您在子组件中更新该道具,或者在父组件中更新该道具,以便两者都会重新渲染。但是,如果数据或状态不依赖于父组件,因此不会在父组件中引起重新渲染。
No, it will not re-render. If you pass any props to the component from the parent component and you update that prop in children or that prop update in the parent component so both will re-render. But if the data or state has no dependency on the parent component so it will not cause a re-render in the parent component.
儿童组件的状态变化对父组件不会影响,但是当父组件的状态更改所有子组件时。
State changes in Child component doesn't effect on the parent component, but when a state of parent component changes all the child components render.
不,就您而言,绝对不是。让我们看看父母何时重新租赁,何时不租用。
案例1:当没有状态从父母转移到子女时,
这是您的情况,父母没有将任何状态转移为道具。在这种情况下,孩子会独立重新租赁,不会导致父母重新渲染。
案例2:在
这种情况下,当用户单击儿童div时,状态
parentstate
更改时,都会在这种情况下进行调整,从/code>和parent
。No, in your case absolutely not. Let's see when the parent re-renders and when not.
Case 1 : When there is no state transfer from parent to child
This is your case, where the parent does not transfer any state as prop. In this case the child re-renders independently, not causing the parent to re-render.
Case 2 : When there is state transfer from parent to child
In this case, whenever the user clicks on the div of Child, the state
parentState
changes, leading to re-render in bothChild
andParent
.