Beginner React Interview QuestionsBeginnerConcept
React · Question 23
What does lifting state up mean in React?
Direct answer
Lifting state up means moving shared state to the closest common parent so multiple child components can read and update one source of truth.
When sibling components must stay synchronized, storing separate copies of the same state creates duplication. Move the state to their common parent and pass values and handlers down as props.
Accordion.jsx
function Accordion() {
const [activeId, setActiveId] = useState(null);
return (
<>
<Panel id="a" activeId={activeId} onSelect={setActiveId} />
<Panel id="b" activeId={activeId} onSelect={setActiveId} />
</>
);
}