Skip to main content
skill CX Codex

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

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add oakoss/agent-skills --skill zustand -a claude-code
Open on GitHub

What 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 createStore and React Context provider.

How to install zustand

1Skills CLI (Vercel)

npx skills add oakoss/agent-skills --skill zustand -a claude-code

2Manually: put the files in place

~/.claude/skills/zustand/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/zustand/

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.

zustand vercel-labs This skill integrates Zustand into json-render to sync application state. Use it when your project already relies on Zustand and you need to connect it with components rendered by json-render. CX Codex +1 1,900installs zustand pedronauck zustand is a Claude Code skill for shaping Zustand stores and shared client state. It activates for store creation, organization, and UI state used across components. CX Codex +1 369installs zustand pproenca A skill with 43 rules for Zustand in React: store architecture, selectors, re-render fixes. Useful when you write or refactor a store. CX Codex +1 463installs zustand bobmatnyc Teaches your agent zustand: a small hook-based state manager for React with no providers. Handy when you need global state but not Redux. CX Codex +1 503installs zustand-patterns OrchestKit zustand-patterns — a skill for Claude Code enforces TypeScript-first patterns for Zustand 5.x state management. Triggers during store creation, slice composition, and middleware setup. CX Codex +1 1,500installs zustand-state-management Mindrally zustand-state-management enforces Zustand store best practices in React and TypeScript apps, covering store slices, SSR, and testing. It helps eliminate selector re-renders and hydration bugs. CX Codex +1 1,000installs zustand-5 prowler-cloud Zustand 5 state management patterns for Claude Code: basic stores, selectors, persist middleware, and slice composition. Prevents unnecessary re-renders and keeps state logic clean. CX Codex +1 912installs zustand-state-builder patricio0312rev zustand-state-builder — a skill for managing app state with Zustand: minimal API, full TypeScript support, persistence, and devtools. Runs on Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, and OpenCode. CX Codex +1 264installs zustand-state existential-birds zustand-state — a skill for Zustand, a lightweight state-management library for React and vanilla JavaScript. CX Codex +1 261installs zustand-store-ts Microsoft zustand-store-ts — a skill for Claude Code and GitHub Copilot that scaffolds Zustand stores with subscribeWithSelector and typed state/action separation. Drop it in when a React project needs global state with fine-grained subscriptions. CX Codex +1 3installs

From the same set106

The whole set →

Project sponsors

Companies that keep this analytics open