简体   繁体   English

React 嵌套子组件的访问状态

[英]React access state of nested child components

I need to access (read and manipulate) the state of a different component.我需要访问(读取和操作)不同组件的状态。 Unfortunately the case isn't just a "simple" Parent <-> Child relation, but a bit more complicated.不幸的是,这种情况不仅是“简单”的 Parent <-> Child 关系,而且有点复杂。

SendResults has a button on which if I click I want to read a state property of the Vote component. SendResults有一个按钮,如果单击该按钮,我想读取Vote组件的状态属性。

I don't really know how to solve this the problem.我真的不知道如何解决这个问题。

Here's the Component Graph:这是组件图:

 Table TableHeader TableBody ResultRow Result Result ParticipantRow Vote Vote TableFooter SendResults

You can use Context API (for a simple use-case like this).您可以使用Context API (对于像这样的简单用例)。

The question that always comes after "Should I use a state management library like Redux or MobX instead" .总是在“我应该使用 Redux 或 MobX 之类的状态管理库来代替”之后出现的问题

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

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