Lifting State Up
Lifting state means moving state to the closest common ancestor of components that need to share it.
function Parent() {
const [name, setName] = useState('');
return (
<>
<Input setName={setName} />
<Display name={name} />
</>
);
}
- This allows multiple child components to sync through shared state.
- Promotes unidirectional data flow.