zustand · oakoss — Claude Code skill: features and installation
Get guidance for Zustand v5 in React, from typed stores and middleware to SSR, tests, and migrations from Redux or Context.
MIT 158 installs ★ 29 updated 2026-08-17
npx skills add oakoss/agent-skills --skill zustand -a claude-codeWhat zustand does
This skill covers client-side global state with Zustand v5: typed stores, selectors, and the persist, devtools, immer, and subscribeWithSelector middleware. It also explains slices for larger stores, SSR and Next.js patterns, vanilla stores, state resets, and testing with Vitest or Jest.
For TypeScript middleware, the skill uses the double-call form create<T>()(...). A global singleton can leak state across SSR requests, so it describes a provider built with createStore and React Context. Zustand requires React 18 or later. Projects using createWithEqualityFn also need use-sync-external-store as a peer dependency.
The material covers hydration troubleshooting and migrations from Redux, Context, or Zustand v4. For server-fetched data that needs caching and revalidation, it points to TanStack Query instead of Zustand.
What it helps with
- configure a typed Zustand v5 store with middleware
- split a large store into domain-based slices
- prevent unnecessary renders with selectors
- set up persistence and debug Next.js hydration
- migrate state from Redux, Context, or Zustand v4
Example prompts for the agent
- Set up a typed Zustand v5 store for the shopping cart and add
persist. - Split this large store into slices and suggest a middleware order.
- Debug Zustand hydration in Next.js and suggest a
createStoreand React Context provider.
How to install zustand
1Skills CLI (Vercel)
npx skills add oakoss/agent-skills --skill zustand -a claude-code2Manually: put the files in place
~/.claude/skills/zustand/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/zustand/
1Skills CLI (Vercel)
npx skills add oakoss/agent-skills --skill zustand -a codex2Manually: put the files in place
.agents/skills/zustand/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add oakoss/agent-skills --skill zustand -a cursor2Manually: put the files in place
.cursor/skills/zustand/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install oakoss/agent-skills skills/zustand2Manually: put the files in place
.github/skills/zustand/SKILL.md1Skills CLI (Vercel)
npx skills add oakoss/agent-skills --skill zustand -a gemini-cli2Platform CLI
gemini skills install https://github.com/oakoss/agent-skills --path skills/zustandManually: put the files in place
.devin/skills/zustand/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add oakoss/agent-skills --skill zustand -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about zustand
How do I install zustand in Claude Code?
Run npx skills add oakoss/agent-skills --skill zustand -a claude-code. The skill file is placed at ~/.claude/skills/zustand/SKILL.md.
What does the zustand skill do?
It guides you through Zustand v5 stores for React, middleware, SSR, and state testing. It also covers migrations from Redux, Context, and Zustand v4.
Which React version does Zustand v5 require?
Use React 18 or later because Zustand relies on useSyncExternalStore. Projects using createWithEqualityFn also need the use-sync-external-store peer dependency.
Source text
SKILL.md · MIT
---
name: zustand
description: |
Zustand v5 state management for React. Covers TypeScript stores with double-parentheses syntax, persist middleware with hydration handling, devtools, subscribeWithSelector, slices pattern for large apps, SSR/Next.js provider pattern, immer middleware, auto-generating selectors, testing, and vanilla stores.
Use when setting up global state, configuring persist middleware, implementing slices pattern, migrating from Redux or Context, testing stores, or troubleshooting hydration and TypeScript issues.
license: MIT
metadata:
author: oakoss
version: '1.0'
source: 'https://zustand.docs.pmnd.rs'
user-invocable: false
---
# Zustand State Management
## Overview
Zustand v5 is a lightweight global state manager for React built on `useSyncExternalStore`. Requires React 18+ (uses `useSyncExternalStore` internally). When using `createWithEqualityFn`, install `use-sync-external-store` as a peer dependency. It provides type-safe stores, atomic selectors for minimal re-renders, composable middleware (persist, devtools, immer, subscribeWithSelector), and a slices pattern for large applications. Use Zustand for client-only global state; use TanStack Query for server-fetched data.
**When to use:** Client-side global state, persistent user preferences, complex multi-domain stores, cross-component state sharing, vanilla (non-React) state management.
**When NOT to use:** Server state with caching needs (use TanStack Query), single-component state (use useState), simple prop drilling scenarios.
## Quick Reference
| Pattern | API | Key Points |
| --------------------- | --------------------------------------- | ------------------------------------------------ |
| Basic store | `create<T>()((set) => ({...}))` | Double parentheses required for TS |
| Atomic selector | `useStore(state => state.bears)` | Only re-renders when selected value changes |
| Multiple values | `useShallow(state => ({a, b}))` | Import from `zustand/react/shallow` |
| Persist | `persist(fn, { name })` | localStorage with SSR hydration handling |
| Devtools | `devtools(fn, { name })` | Redux DevTools integration |
| SubscribeWithSelector | `subscribeWithSelector(fn)` | Subscribe to state slices outside React |
| Middleware order | `devtools(persist(fn))` | Outer to inner wrapping |
| Slices pattern | `StateCreator<Combined, [], [], Slice>` | Split store by domain |
| SSR provider | `createStore` + React Context | Per-request stores prevent data leaks |
| Immer | `immer(fn)` | Safe nested state mutations |
| Vanilla store | `createStore` from `zustand/vanilla` | Use outside React |
| Reset store | `set(store.getInitialState())` | Use `getInitialState()` for reliable reset |
| Derived values | `useStore(s => s.items.length)` | Compute in selector |
| Auto selectors | `createSelectors(store)` | Generate `store.use.field()` hooks automatically |
## Common Mistakes
| Mistake | Correct Pattern |
| ------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- |
| Using `create<T>(...)` with single parentheses | Use `create<T>()(...)` double parentheses for correct TypeScript middleware inference |
| Selecting full state object with `useStore(state => state)` | Use atomic selectors like `state.bears` or `useShallow` to avoid unnecessary re-renders |
| Importing `useShallow` from `zustand/shallow` | Import from `zustand/react/shallow`; `zustand/shallow` exports the plain `shallow` function only |
| Creating new object references in selectors causing infinite loops | Use separate primitive selectors or wrap with `useShallow` from `zustand/react/shallow` |
| Using a global singleton store with SSR or Next.js | Use the `StoreContext` provider pattern with `createStore` to prevent data leaks between requests |
| Tracking initial state manually for reset | Use `store.getInitialState()` which Zustand provides automatically |
| Using Zustand for server-fetched data that needs caching and revalidation | Use TanStack Query for server state; reserve Zustand for client-only global state |
## Delegation
- **Store architecture and slices design**: Use `Plan` agent to define domain boundaries, slice interfaces, and middleware composition order
- **Hydration and SSR debugging**: Use `Task` agent to diagnose persist middleware issues, hydration mismatches, and Next.js provider setup
- **Migration from v4 to v5**: Use `Explore` agent to find deprecated import paths, single-parentheses patterns, and legacy middleware usage
- **Testing strategy**: Use `Task` agent to set up store mocks and test isolation patterns
## References
- [Store patterns, TypeScript, and core API](references/store-patterns.md)
- [Middleware: persist, devtools, immer, subscribeWithSelector, and custom](references/middleware.md)
- [Slices pattern and large store architecture](references/slices-pattern.md)
- [SSR, Next.js, and hydration handling](references/ssr-hydration.md)
- [Testing stores with Vitest and Jest](references/testing.md)
- [Migration guide: Redux, Context, and v4 to v5](references/migration.md)
© oakoss · MIT · oakoss/agent-skills
Similar skills
All skills for Frontend and UI →zustand by other authors comes first.