# Zustand — card for AI agents

Lightweight state management for React with minimal boilerplate.

Category: State and data fetching · npm package `zustand` · latest version 5.0.16 (checked 2026-11-01)
Install: `npm install zustand`
License: MIT (permissive)

In your own product (generator, app, hosted service): **yes**. Permissive license: ship it inside your own product, closed or open source, and keep its license and copyright notice.

## Rules for AI agents (paste into AGENTS.md or CLAUDE.md)

## 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()(...)` 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.

## Agent Skills for it
- zustand-store-ts from microsoft/skills: `npx skills add microsoft/skills --skill zustand-store-ts`

## Docs written for agents
- [llms.txt (index of the docs)](https://zustand.docs.pmnd.rs/llms.txt)

## What it is
- Zustand is a state-management library. The README describes it as "a small, fast and scalable bearbones state-management solution using simplified flux principles" with a hook-based API. You call `create` with a function that receives `set` (and optionally `get`). It returns a hook that holds state and actions together: primitives, objects and functions.
- Components call that hook with a selector and re-render only when the selected value changes. The default comparison is strict equality. `useShallow` handles object and array picks. Middleware adds persistence, Redux DevTools, Immer-style updates, a Redux-like reducer and selector subscriptions. A vanilla `createStore` from `zustand/vanilla` drops the React dependency.
- The comparison page in the docs says Zustand is "based on an immutable state model" and is "a single store". It also says render optimization is done by hand with selectors. The project is MIT licensed and its repository dates from April 2019.

## Caveats
- Render optimization is your job: 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.
- Object selectors need useShallow: Change detection is strict equality by default. A selector that builds a new object or array needs `useShallow` to avoid unnecessary rerenders.
- Replace mode can delete your actions: Passing `true` as the second argument to `set` replaces the whole state instead of merging it. Actions stored in the state get wiped too.
- Not for state in React Server Components: The README warns against using the outside-component `getState`/`setState` technique to add state in React Server Components.
- Middleware does not wrap getState/setState: If a middleware changes `set` or `get`, calls made through the vanilla `getState` and `setState` bypass it.

## Numbers (AgentGid data)
- Gid Score: 88.3 (#14 of all tools, 1 of 53 in its category)
- Used in 366 public projects set up for AI coding agents (5.8%)
- Downloads last week: 96,888,255 (as of 2026-11-24), +52.4% over 4 weeks
- GitHub stars: 58,985 (as of 2026-11-24)
- Last push: 2026-11-23

## Often used with
React 98.6%, Lucide React 68.0%, clsx 65.0%, Tailwind CSS 84.7%, Tailwind Merge 62.8%, Class Variance Authority 55.2%

## Checked alternatives (same job)
- Jotai: https://agentgid.com/tools/jotai/agent.md

## Links
- AgentGid page: https://agentgid.com/tools/zustand/
- Homepage: https://github.com/pmndrs/zustand
- Repository: https://github.com/pmndrs/zustand
- Source: https://github.com/pmndrs/zustand#readme
- Source: https://github.com/pmndrs/zustand
- Source: https://github.com/pmndrs/zustand/releases
- Source: https://zustand.docs.pmnd.rs/llms.txt
- Source: https://zustand.docs.pmnd.rs/learn/getting-started/introduction.md
- Source: https://zustand.docs.pmnd.rs/learn/getting-started/comparison.md

---
AgentGid's catalog is curated: every entry was checked against the maker's official pages (registry, repository, license and pricing pages) on the date shown; a license value shows the quote it stands on wherever AgentGid has one. Usage numbers come from AgentGid's own scan of public repositories set up for AI coding agents. Claims by makers are reported, not tested by AgentGid.
