Choosing State Location
Ask three questions: who owns this data, who needs it, and where does it persist?
Local UI state such as an open dropdown should usually remain local. State shared by sibling components can be lifted. Data needed across distant branches may justify context or an external store. State that should survive refresh or be shareable through a link may belong in the URL or server.
A common architectural failure is making every value global because global state feels convenient. Global state increases coupling and makes ownership harder to reason about.
State Placement Decision
Key Takeaways
- State location is an architecture decision.
- Prefer the narrowest ownership that satisfies requirements.
- URL state and server state are different categories from ephemeral UI state.