[英]Does React update the parent contexts when a child context is updated?
I am using unstated-next for state management.我正在使用 unstated-next 进行 state 管理。 And for my application I am having multiple containers.对于我的应用程序,我有多个容器。 Which created multiple React Contexts.它创建了多个 React 上下文。 And the providers are nested one under the other.提供者一个一个地嵌套在另一个下面。 You can assume like layers.你可以假设像层。 Let layer 3 be the outermost layer and layer 1 being the innermost layer of the entire app.假设第 3 层是最外层,第 1 层是整个应用程序的最内层。 When I update the layer 1. Will the state within layer 2 and layer 3 get back to their initial state?当我更新第 1 层时,第 2 层和第 3 层中的 state 是否会恢复到其初始的 state?
<Layer3.Provider initialState={[]}>
<Layer2.Provider initialState={{}}>
<Layer1.Provider>
my components
</Layer1.Provider>
</Layer2.Provider>
</Layer3.Provider>
Nope.没有。 A component's state is private to the component.组件的 state 是组件私有的。 Changing state of a child will never cause parent state to change.改变孩子的 state 永远不会导致父母 state 改变。 A parent state change might trigger a re-render for child but not the other way round.父级 state 更改可能会触发子级的重新渲染,但反之则不会。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.