简体   繁体   中英

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.

SendResults has a button on which if I click I want to read a state property of the Vote component.

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).

The question that always comes after "Should I use a state management library like Redux or MobX instead" .

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