ReactIntermediate#state#patterns

What is lifting state up?

Moving shared state to the closest common ancestor of the components that need it, then passing the value down as props and changes back up through callbacks, so both stay in sync.

Example
function Parent() {
  const [q, setQ] = useState('');
  return <><Search value={q} onChange={setQ} /><Results q={q} /></>;
}

Related Questions

1
ReactIntermediate#patterns#context

What is prop drilling and how do you avoid it?

Open
2
ReactBeginner#patterns

What is the children prop and composition?

Open
3
ReactBeginner#jsx

What are fragments and why use them?

Open