Zustand
Lightweight state management for React with minimal boilerplate.
3. Used by agents' projects
Dependency in 366 public GitHub projects set up for AI coding agents that we scanned (5.8%).
4. Agent access
Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.
zustand.docs.pmnd.rs/llms.txtFrom the package registry and GitHub, checked daily. Tap a verdict to see its source.How we checkedReport an error
What Zustand does
In Zustand the store itself is a React hook. Components select slices from it directly, with no provider around the app, and the same store can run outside React.
Zustand popularity
Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated
How Zustand is used
- Zustand is a dependency in 366 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (7.5% of the 4,867 JavaScript/TypeScript ones), #2 of 53 in state and data fetching.
- Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 1,301; those are left out of every share on this page.
- The most used alternative in our scan is Jotai (35 projects).
- Projects that use it most often also use React (98.6%), Lucide React (68.0%), clsx (65.0%).
- It is more common in projects set up for Kiro (10.7%) than for OpenAI Codex (5.3%).
By coding agent
Often used with
Zustand in practice
Strengths
You define state and actions in one <code>create</code> call and use the returned hook in any component. Nothing has to wrap the app.
The docs say a lot of work went into the zombie child problem, React concurrency, and context loss between mixed renderers. They add that it "may be the one state manager in the React space that gets all of these right."
<code>createStore</code> from <code>zustand/vanilla</code> returns <code>getState</code>, <code>setState</code>, <code>subscribe</code> and <code>getInitialState</code> instead of a hook. You can bind it back to React later with <code>useStore</code>.
For state that changes often, a component can <code>subscribe</code> and write into a ref instead of re-rendering. The README pairs this with <code>useEffect</code> so the subscription is removed on unmount.
Watch out for
The docs state plainly that you apply render optimizations by hand with selectors. Calling the hook with no selector re-renders the component on every state change.
Change detection is strict equality by default. A selector that builds a new object or array needs <code>useShallow</code> to avoid unnecessary rerenders.
Passing <code>true</code> as the second argument to <code>set</code> replaces the whole state instead of merging it. Actions stored in the state get wiped too.
Create a store and bind components
import { create } from 'zustand'
const useBearStore = create((set) => ({
bears: 0,
increasePopulation: () => set((state) => ({ bears: state.bears + 1 })),
removeAllBears: () => set({ bears: 0 }),
}))
function BearCounter() {
const bears = useBearStore((state) => state.bears)
return <h1>{bears} around here ...</h1>
}
function Controls() {
const increasePopulation = useBearStore((state) => state.increasePopulation)
return <button onClick={increasePopulation}>one up</button>
}More about Zustand
Funding
- GitHub Sponsors: https://github.com/dai-shi
- Own page: https://daishi.gumroad.com/l/uaxms
- Own page: https://daishi.gumroad.com/l/learn-zustand-v4
- 21 GitHub sponsors
Agent Skills for it
- zustand-store-ts: Create Zustand stores with TypeScript, subscribeWithSelector middleware, and proper state/action separation. Use when building React state m
Packages around it
- react: UI library
- tailwindcss: Utility-first CSS
- clsx: className builder
- lucide-react: Icon components
- eslint: JS/TS linter
- tailwind-merge: Tailwind class merging
More in State and data fetching
Alternatives
Zustand This page
Minimal React state management with atoms as primitive building blocks for flexibility.
Get started
Install it.
npm install zustandRules for your agent
## Zustand
- Always pass a selector to the store hook, e.g. `useBearStore((state) => state.bears)`. Calling it with no selector re-renders the component on every state change.
- When a selector returns a new object or array, wrap it in `useShallow` from `zustand/react/shallow`. The default comparison is strict equality.
- Update state immutably. `set` merges the top level. Never pass `true` as the second argument unless you mean to replace the whole state, actions included.
- For Map and Set values, create new instances on every update.
- Do not add state in React Server Components with the module-level `getState`/`setState` technique. The README warns about bugs and privacy issues (typically Next.js 13 and above).
- In TypeScript, write `create<State>()(...)` instead of `create(...)`.
- For dependency injection through React context, put a vanilla `createStore` store in the context and read it with `useStore`. Do not put the hook itself in context.