Lifting State Up
When two components need the same data, move the state to their closest common parent and pass it down with props and callbacks.
Example
function Parent() {
const [text, setText] = useState('');
return (
<>
<Input value={text} onChange={setText} />
<Preview text={text} />
</>
);
}Exercise
Where should shared state live?
The common Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.