There are two decisions: where each piece of state lives, and whether it should be state at all.
Where. Put state in the closest common parent of every component that reads or changes it. When two siblings need the same value, lift it up: move it into their parent and pass down the value plus a callback to change it. Each piece of state then has one owner, a single source of truth. Don't lift higher than needed: an update re-renders the owner's whole subtree. Values that many distant components need can go through context; server data, URL state and form libraries are separate kinds of state with their own tools, and shared stores outside React are read with useSyncExternalStore.
What not to store. Keep the minimal set of values you can't compute. Before adding a useState, ask:
- Can it be calculated from props or other state? Compute it during render (
useMemoonly if slow). Don't sync it with an effect. - Is it a copy of a prop?
useState(props.color)uses the prop only as the initial value and ignores later changes. Read the prop directly, or name itinitialColorif only the first value matters. To start over when an identity changes, reset with akey. - Is it duplicated? Store
selectedId, not a copy of the selected object, and find the object during render. - Can values contradict each other? Replace
isSendingandisSentwith onestatus: 'typing' | 'sending' | 'sent'. - Do values always change together? Group them into one object, or a reducer.
- Is it deeply nested? Flatten it into objects keyed by id.
The aim is a structure where invalid combinations can't be represented and every change is made in exactly one place.