In React's unidirectional data flow, data flows strictly top-down from parent to child. Sibling components cannot directly communicate with one another or pass state horizontally.
Consider a common scenario:
AccordionHeader or a SearchInputAccordionContent or a SearchResultsListIf Component A holds state in its own local useState, Component B has no way of reading that state or reacting to its changes.
To share state between two or more sibling components:
Child 1 (SearchInput) receives the current search term and a callback:
Child 2 (SearchResults) receives the filtered list:
The parent component (CourseDirectory) owns the query state and coordinates data flow:
Lifting state up establishes a single source of truth. Instead of trying to keep local copies of data synchronized across multiple sibling components, one component acts as the authority. This architectural discipline prevents out-of-sync UI states and simplifies debugging.
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| Updating State and Immutable Updates | Handling Synthetic Events in React |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.
Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.