Skip to content
Development
Skill

/zustand-patterns

Reference for Zustand 5.x state management including slices, middleware, Immer, useShallow, persistence, selectors, and devtools integration. Documents 7 core patterns with TypeScript examples and anti-patterns. Use when building React state management with Zustand instead of

From plugin
orchestkit
301122 skills36 agents

Claude Code

$ npx -y skills add yonatangross/orchestkit --skill zustand-patterns --agent claude-code

SKILL.md

zustand-patterns.SKILL.md
name: zustand-patterns
license: MIT
compatibility: "Claude Code 2.1.277+."
description: "Reference for Zustand 5.x state management including slices, middleware, Immer, useShallow, persistence, selectors, and devtools integration. Documents 7 core patterns with TypeScript examples and anti-patterns. Use when building React state management with Zustand instead of Redux."
context: inherit
allowed-tools: "Read Write Grep Glob"
user-invocable: false
disable-model-invocation: true
effort: low
targets:
  - library: zustand
    version: ">=5.0.0"
model: haiku
metadata:
  category: document-asset-creation
  version: "1.0.0"
  author: "OrchestKit"
  complexity: "low"
  tags: "zustand, state-management, react, immer, middleware, persistence, slices"
path_patterns: ["**/store/**", "**/stores/**", "*.store.*", "*.zustand.*"]

Zustand Patterns

Modern state management with Zustand 5.x - lightweight, TypeScript-first, no boilerplate.

Overview

  • Global state without Redux complexity
  • Shared state across components without prop drilling
  • Persisted state with localStorage/sessionStorage
  • Computed/derived state with selectors
  • State that needs middleware (logging, devtools, persistence)

Upstream coverage (do not restate)

Zustand's own docs are the source for the mechanics. This skill carries only the OrchestKit delta on top of them, in `references/ork-delta.md`, the `rules/` files, and the checklist.

| Topic | First-party source | |-------|--------------------| | Basic store, `create<State>()()`, actions, async actions | https://github.com/pmndrs/zustand/blob/main/docs/reference/apis/create.md | | Slices pattern (splitting and combining stores) | https://github.com/pmndrs/zustand/blob/main/docs/learn/guides/slices-pattern.md | | Typing slices and middleware mutator tuples | https://github.com/pmndrs/zustand/blob/main/docs/learn/guides/advanced-typescript.md | | Immer middleware (draft mutations) | https://github.com/pmndrs/zustand/blob/main/docs/reference/middlewares/immer.md | | persist: `partialize`, `version`, `migrate`, `onRehydrateStorage`, storage adapters | https://github.com/pmndrs/zustand/blob/main/docs/reference/middlewares/persist.md | | devtools: action names, `enabled`, `serialize`, `trace` | https://github.com/pmndrs/zustand/blob/main/docs/reference/middlewares/devtools.md | | `subscribeWithSelector` and non-React subscriptions | https://github.com/pmndrs/zustand/blob/main/docs/reference/middlewares/subscribe-with-selector.md | | Selectors and `useShallow` re-render control | https://github.com/pmndrs/zustand/blob/main/docs/learn/guides/prevent-rerenders-with-use-shallow.md | | v4 to v5 migration (`createWithEqualityFn`, React 18 floor) | https://github.com/pmndrs/zustand/blob/main/docs/reference/migrations/migrating-to-v5.md | | SSR and hydration | https://github.com/pmndrs/zustand/blob/main/docs/learn/guides/ssr-and-hydration.md | | Store testing and reset | https://github.com/pmndrs/zustand/blob/main/docs/learn/guides/testing.md | | Server-state ownership (use TanStack Query, not Zustand) | https://tanstack.com/query/latest/docs/framework/react/guides/does-this-replace-client-state |

Quick Reference

// ✅ Create typed store with double-call pattern
const useStore = create<State>()((set, get) => ({ ... }));

// ✅ Use selectors for all state access
const count = useStore((s) => s.count);

// ✅ Use useShallow for multiple values (Zustand 5.x)
const { a, b } = useStore(useShallow((s) => ({ a: s.a, b: s.b })));

// ✅ Middleware order: immer → subscribeWithSelector → devtools → persist
create(persist(devtools(immer((set) => ({ ... })))))

// ❌ Never destructure entire store
const store = useStore(); // Re-renders on ANY change

// ❌ Never store server state (use TanStack Query instead)
const useStore = create((set) => ({ users: [], fetchUsers: async () => ... }));

Key Decisions

| Decision | Option A | Option B | Recommendation | |----------|----------|----------|----------------| | State structure | Single store | Multiple stores | **Slices in single store** - easier cross-slice access | | Nested updates | Spread operator | Immer middleware | **Immer** for deeply nested state (3+ levels) | | Persistence | Manual localStorage | persist middleware | **persist middleware** with partialize | | Multiple values | Multiple selectors | useShallow | **useShallow** for 2-5 related values | | Server state | Zustand | TanStack Query | **TanStack Query** - Zustand for client-only state | | DevTools | Always on | Conditional | **Conditional** - `enabled: process.env.NODE_ENV === 'development'` |

Anti-Patterns & Integration

Forbidden patterns (store destructuring, derived state, server state, direct mutation) and React Query integration guidance.

Load Read("references/anti-patterns-and-integration.md") for anti-pattern examples and TanStack Query separation patterns.

Related Skills

  • `react-server-components-framework` - RSC hydration considerations with Zustand
  • Server state: https://tanstack.com/query/latest/docs/framework/react/guides/does-this-replace-client-state
  • Form state: https://react-hook-form.com/docs/useform

Capability Details

store-creation

**Keywords**: zustand, create, store, typescript, state **Solves**: Setting up type-safe Zustand stores with proper TypeScript inference

slices-pattern

**Keywords**: slices, modular, split, combine, StateCreator **Solves**: Organizing large stores into maintainable, domain-specific slices

middleware-stack

**Keywords**: immer, persist, devtools, middleware, compose **Solves**: Combining middleware in correct order for immutability, persistence, and debugging

selector-optimization

**Keywords**: selector, useShallow, re-render, performance, memoization **Solves**: Preventing unnecessary re-renders with proper selector patterns

persistence-migration

**Keywords**: persist, localStorage, sessionStorage, migrate, version **Solves**: Persisting state with schema migrations

Read more
@yonatangross
Ships withorchestkit

The Complete AI Development Toolkit for Claude Code. 115 skills, 36 agents, 163 hooks. Install `ork` for stable (v10.x).

301122 skills36 agents
Get the whole plugin

Stars on GitHub

Momentum

stars in total
301
Star history of yonatangross/orchestkit on GitHub, a chart by star-history.com

Other skills on orchestkit.

ork-assess

ork-assess

Assess a code change, design, architecture, workflow, or competing options against explicit criteria and evidence. Use when a…

ork-brainstorm

ork-brainstorm

Compare plausible implementation, architecture, product, or operational approaches before committing to one. Use when a request…

ork-explore

ork-explore

Map an unfamiliar codebase, feature, architecture, data flow, or operational path with file-backed evidence. Use when a request…

ork-glyph

ork-glyph

Render an answer inline as compact ASCII or box-drawing art with semantic status icons. Use for status, inventories, budgets,…

ork-implement

ork-implement

Make an approved, scoped change and prove the affected behavior. Use when a request asks to implement, build, add, or land a…

ork-review-pr

ork-review-pr

Review a pull request or branch for correctness, regressions, security, operational risk, and missing evidence. Use when a…

More skills from other plugins.

brainstorming
Auto-invoked

brainstorming

You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or…

@obra@obraInstall Skill
ask-matt

ask-matt

Ask which skill or flow fits your situation. A router over the skills in this repo.

skills11d309k
@mattpocock@mattpocockInstall Skill
accessibility
Auto-invoked

accessibility

Design, implement, and audit accessible UI to WCAG 2.2 Level AA across Web, iOS, and Android — semantic ARIA roles and labels,…

ecc12d293k
@affaan-m@affaan-mInstall Skill
compiler-commit

compiler-commit

Use when you want to verify compiler changes and commit with the correct convention. Runs tests, lint, and format, then commits…

react2d252k
@facebook@facebookInstall Skill

Questions about zustand-patterns.

Which coding agents can use zustand-patterns?
zustand-patterns installs in Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, OpenCode and Windsurf with the skills CLI, using each agent's flag shown on this page. Flowy's auto-invocation, which fires a skill when your prompt matches, runs in Claude Code only.