Zustand
Minimal React state management library with a hooks-based API, no Provider wrapper required, supporting slice pattern for modular state, and middleware for persistence, devtools, and immer-based immutable updates.
Score Breakdown
⚙ Agent Friendliness
🔒 Security
No network security surface. Sensitive state (tokens, PII) stored via persist middleware writes to localStorage in plaintext — avoid persisting secrets or sanitize before persist.
⚡ Reliability
Best When
Managing client-side UI state in React applications where Redux Toolkit feels like overkill and you want minimal boilerplate with TypeScript support and tiny bundle size (~1KB).
Avoid When
Your state is primarily server-derived data that needs caching and synchronization — TanStack Query or Apollo Client are better fits for that pattern.
Use Cases
- • Create a global store for UI state (user session, theme, modals) with a single create() call and use it in any component without a Provider
- • Implement the slice pattern to split a large store into domain-specific slices (authSlice, cartSlice) that compose into one store
- • Persist store state to localStorage using the persist middleware with automatic rehydration on page load
- • Use subscribeWithSelector middleware to subscribe to fine-grained store slices from outside React (e.g., in a service or event handler)
- • Integrate immer middleware for complex nested state mutations using mutable syntax while keeping the store immutable under the hood
Not For
- • Server state management (API fetching, caching, background sync) — use TanStack Query for that
- • Applications needing strict Redux-style action dispatching with time-travel debugging via Redux DevTools (though Zustand devtools middleware exists)
- • Teams that need the formal reducer/action/selector pattern for large-scale state architecture
Interface
Authentication
No auth layer — Zustand is a client-side state library. Auth state is commonly stored in a Zustand store but auth logic is external.
Pricing
MIT licensed. Maintained by Poimandres open source collective.
Agent Metadata
Known Gotchas
- ⚠ Zustand v5 removed the deprecated get() argument from set() — code using set((state) => ...) is fine but set(get => ...) syntax from older tutorials will break
- ⚠ Selectors passed to useStore must be stable references or wrapped in useShallow; inline selector functions cause infinite re-renders on every state change
- ⚠ The persist middleware stores state as JSON; class instances, Maps, Sets, and non-serializable values will be lost on rehydration and must be handled in the onRehydrateStorage callback
- ⚠ Zustand stores created with create() are module-level singletons; in test environments, always reset the store between tests or state leaks between test cases
- ⚠ Accessing store state outside React components via getState() returns a snapshot and does not subscribe to updates — use subscribe() for reactive non-React listeners
Alternatives
Full Evaluation Report
Detailed scoring breakdown, competitive positioning, security analysis, and improvement recommendations for Zustand.
Scores are editorial opinions as of 2026-03-06.