Lifting state up means moving shared state to the closest common parent. This way, siblings get the same data from one place, making updates consistent and easier to manage.
If siblings keep separate state copies, changes in one won't reflect in the other. This causes UI inconsistencies and bugs.
function Parent() { const [count, setCount] = React.useState(0); return ( <> <ChildButton count={count} onClick={() => setCount(count + 1)} /> <ChildDisplay count={count} /> </> ); } function ChildButton({ count, onClick }) { return <button onClick={onClick}>Increment: {count}</button>; } function ChildDisplay({ count }) { return <p>Current count: {count}</p>; }
Since the count state is in Parent, updating it triggers re-render of both children. Both show the updated count.
Correct lifting means the parent owns the state and passes it down. Children use props to read and callbacks to update.
function Parent() { const [count, setCount] = React.useState(0); const increment = React.useCallback(() => { setCount(count + 1); }, []); return <ChildButton onClick={increment} />; } function ChildButton({ onClick }) { return <button onClick={onClick}>Increment</button>; }
The increment function captures the count value when Parent renders. It does not see updated count on later clicks, causing stale state updates.
