The first question I ask when reviewing a frontend architecture is: where does the state live relative to where it is used?
In most codebases I have reviewed, the answer is "in a global store, regardless of scope." This is the wrong default.
The rule
State should live as close to its consumers as possible. If only one component needs it, it is component state. If a subtree needs it, it is a context or service scoped to that subtree. Global state is for truly global concerns: authentication, locale, theme.
Originally published on ysndmr.com.
Top comments (0)