Deleting 80% of Zustand Stores Cut Code in Half and Fixed Bugs
Global state libraries are a reflex in React projects, but this refactor shows a measurable cost: redundant renders, fragile dependencies, and unreadable code. Co-locating state with local hooks and Context can deliver better performance and maintainability without abandoning the ecosystem.
A frontend engineer on a two-year-old mid-office project found that Zustand stores had become an uncontrolled global garbage bin. One modal's visibility state was buried in `useUIStore` alongside login state, theme, and table sorting. Checking a row in a 500-row table triggered a full-site re-render, and mysterious bugs (input losing focus, modals closing instantly) were impossible to trace because 15 places could mutate `isOpen`.
The fix was state co-location: keep state as close to its usage as possible. The modal switch became a local `useState`, page-level shared state like table filters moved to Context + useReducer, and only `userToken` and `theme` stayed in Zustand. The result: code volume dropped by half, bugs disappeared, and frame rate stabilized at 60fps. The author also notes that AI coding assistants amplify the problem—they love `import { useStore }` in any component, and they suggest splitting stores into more sub-stores rather than questioning whether the state belongs globally at all.
The real culprit isn't Zustand itself but the habit of promoting any temporary UI state to global scope; the library only makes that habit frictionless.
AI coding tools amplify over-globalization because they optimize for easy feature assembly, not for architectural cleanliness.
A store with more than ten unrelated states is a strong smell that it's become a dumping ground; local hooks or Context often solve the problem with far less overhead.
The performance win here came not from optimizing renders but from eliminating the global render trigger altogether.