React › Props & State

How does lifting state up work in React, and when should you use this pattern?

Advanced

Answer

Lifting state up means moving a piece of state from a child component up to their closest shared parent, so multiple sibling components can read and update the same data. This is needed whenever two components that do not directly relate to each other need to stay in sync with the same information.
function Parent() {
  const [selectedColor, setSelectedColor] = useState('blue');
  return (
    <>
      <ColorPicker selectedColor={selectedColor} onSelect={setSelectedColor} />
      <Preview color={selectedColor} />
    </>
  );
}
Real-world example A design tool keeps the currently selected color in the shared parent component, so both the color picker and the live preview panel, which sit as separate sibling components, always stay perfectly in sync with each other.

Common follow-ups: What is the downside of lifting state too high up in a large component tree?;When would Context be a better solution than lifting state up?