October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

How to Keep React Components in Sync by Lifting State Up

Keep React siblings in sync by lifting their shared state to the closest common parent and passing values and update callbacks down as props.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To share data between React components, move the shared state into their closest common parent, then pass the current value and any update callbacks down as props. The parent becomes the single source of truth for that value, so sibling components stay coordinated after a change.

Why independent child state cannot keep siblings in sync

A component owns the state it declares. If two child components each store their own isActive boolean, each can open or close independently; neither child’s state automatically updates the other. A parent also cannot directly change a child’s private local state. To coordinate the children, move the shared value to a component that contains both.

As an Amazon Associate I earn from qualifying purchases.

How to lift state to the common parent

  1. Make the children receive the shared value as a prop. Remove the duplicated isActive state from each panel and let each panel render based on its isActive prop.
  2. Find the closest common parent. In an accordion, the component rendering both panels is the natural owner of their shared selection.
  3. Store the value in that parent and pass it down. The parent derives each child’s prop from its state and supplies an event handler such as onShow.
  4. Have the child request changes through the handler. When a user selects a panel, the child calls the callback; the parent updates its state and React renders the children with the new props.

This is the pattern React calls “lifting state up”: state moves from coordinated children to their common parent, while props and callbacks carry data and update requests in the opposite direction. See React’s guide to sharing state between components.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose state that makes the interface rule explicit

Only one accordion panel may be open

If the interface allows only one open panel at a time, keep one selection in the parent, such as activeIndex, rather than separate booleans. For two panels, the first can be active when activeIndex === 0, and the second when activeIndex === 1. Selecting a panel sets that single value. This state shape represents the rule directly: there is only one active selection.

Two inputs must show the same text

For synchronized inputs, store one text value in their common parent and pass that value and a change handler to both inputs. Editing either input requests an update to the parent’s value; on the next render, both receive the same text. Separate state values would require extra coordination and could drift apart.

Which component should own a piece of state?

React’s guidance is to choose one owner for each unique piece of state: “For each unique piece of state, you will choose the component that ‘owns’ it.” The owner should be the component that can coordinate the relevant consumers without placing the value unnecessarily high in the tree. State that no other component needs can remain local to a leaf; lifting state does not mean moving all application state to the root. React explains this ownership principle in its state-sharing guide and its Thinking in React guide.

A component whose important information is driven by props is often called controlled; one that manages that information with its own state is often called uncontrolled. These terms describe useful design patterns, not rigid technical categories. A component can receive props while still keeping unrelated local state.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When props are enough—and when to consider context

For a few nearby siblings, props make the relationship easy to see: the parent owns the value, and children receive it along with callbacks for requesting changes. If many layers sit between the owner and the components that need the value, forwarding the same prop through each intermediate component can become cumbersome. React calls this prop drilling and documents context as an option for making information available to deeper descendants without passing it through every layer.

Context is a boundary to consider when repeated forwarding becomes inconvenient, not an automatic replacement for lifting state. The choice is about the shape and reach of the data flow; the cited React guidance does not establish a performance advantage for context over props.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Quick decision guide

Situation Where the value belongs How components receive it
One component uses a value privately Keep it in that component Local state
Nearby siblings must coordinate one value Their closest common parent Pass the value and callbacks as props
Many deeper descendants need a value and repeated prop forwarding is awkward Choose an appropriate provider/owner in the tree Consider context

The examples and principles above are presented in React’s official learning documentation, which does not identify a specific React version on the cited pages. For current wording and examples, consult the live documentation links.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.