Skip to content
Core ConceptsChapter 14 / 37Intermediate4 min read

Lifting State Up

Learn what lifting state up means in React, moving state to a common parent so sibling components can share the same data, with a worked example.

On this page

1. What is lifting state up?

This is called "lifting state up". The parent becomes the owner of the state. Children receive the value through props, plus a function prop to update it.

2. Why does it matter?

Siblings cannot talk to each other directly. Data only flows from top to bottom. If each one has its own state, they drift out of sync.

Each child has its own stateState lives in the parent
Two copies, different valuesOne source of truth
One panel opens and the other does not knowThe parent decides which one is open
Hacks to keep them in syncAutomatically in sync
Bugs and confusionPredictable data flow

3. Where is it used?

Use caseShared state
AccordionWhich panel is open
Search + resultsThe search query
Temperature converterCelsius and Fahrenheit from one value
Cart icon + product pageThe count of cart items
Filters + tableThe selected filters

4. How does it work?

State goes up, data goes down, events go up
Keep the state in the common parent
The parent passes the value to children through props
The parent also passes the update function as a prop
The child calls that function on an event
The parent's state changes and all children re-render

A simple way to remember this pattern: data flows down, events flow up.

5. Code example

Accordion: one panel at a time

jsx
import { useState } from "react";

function Panel({ title, isActive, onShow, children }) {
  return (
    <section>
      <h3>{title}</h3>
      {isActive ? <p>{children}</p> : <button onClick={onShow}>Show</button>}
    </section>
  );
}

export default function Accordion() {
  const [activeIndex, setActiveIndex] = useState(0);

  return (
    <>
      <Panel
        title="Delivery"
        isActive={activeIndex === 0}
        onShow={() => setActiveIndex(0)}
      >
        Delivery in 2 to 4 days.
      </Panel>
      <Panel
        title="Returns"
        isActive={activeIndex === 1}
        onShow={() => setActiveIndex(1)}
      >
        You can return it within 7 days.
      </Panel>
    </>
  );
}

How does the code work?

PartMeaning
activeIndexThe state lives in the parent Accordion, not in the children
isActive propEach Panel only receives a boolean
onShow propCarries the child's click up to the parent
setActiveIndex(1)The parent updates, and both panels get new props

Now Panel is a controlled component: its behavior is controlled by the parent's props, not by its own state.

6. Common mistakes

Mistake: Copying state into every child and syncing it with effects

Why? You end up with two sources of truth, and if one update is missed the UI shows the wrong data.

Better: Keep the state in one place, the common parent, and share it through props.

Mistake: Lifting state higher than needed, like putting everything in App

Why? A tiny change re-renders the whole tree and App becomes very heavy.

Better: Lift the state only as far as the closest common ancestor of the components that need it.

Mistake: Giving the child the setter directly so it needs to know the shape of the parent's state

Why? The child becomes tied to the parent's internal details, and it is hard to reuse.

Better: Give the child a meaningful event prop like onShow or onSelect, and keep the logic in the parent.

Interview tip

"How do you share data between siblings?" The first answer is always lifting state up. If the tree is very deep, use context or a state management library.

7. What to learn before and after

Final quick revision

PointDetail
WhenTwo components need the same data
WhereThe closest common parent
DataDown through props
EventsUp through function props
BenefitA single source of truth