Lifting State Up

Lifting state up is moving shared state to the closest common parent of the components that need it, then passing it down as props. It lets sibling components stay in sync through a single source of truth.

React

When two components need the same data, you shouldn't keep separate copies in each. Instead, you move (lift) that state up into their nearest shared parent. The parent owns the state and passes both the value and an updater function down as props.

This pattern keeps data consistent and predictable: there is one source of truth, and child components communicate by calling functions the parent gave them. When state needs to be shared very widely across the app, the Context API can reduce the prop passing.

Examples

JSX — The parent owns the text state and shares it with both the input and the paragraph, keeping them in sync.

import { useState } from "react";

function Parent() {
  const [text, setText] = useState("");
  return (
    <>
      <input value={text} onChange={(e) => setText(e.target.value)} />
      <p>You typed: {text}</p>
    </>
  );
}

Learn it in a lesson

See also

Back to the Dictionary