Agent skill

Zustand State Management

by Mindrally in Mindrally/skills

Best practices for Zustand state management in React and TypeScript applications, covering store design, selectors, middleware, SSR, and testing.

Apache-2.0Auto-check passedFrontend & Design

Install Zustand State Management

skills CLI
$ npx skills add Mindrally/skills --skill zustand-state-management -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install Mindrally/skills zustand-state-management --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/Mindrally/skills.git skills-src && mkdir -p .claude/skills && cp -r skills-src/zustand-state-management .claude/skills/zustand-state-management && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
zustand-state-management
GitHub stars
271
Token cost
~1.8k tokens
SKILL.md length
737 words
Files
1
Skills in repo
34
Repo updated
First seen
Licence
Apache-2.0

At a glance

Best practices for Zustand state management in React and TypeScript applications, covering store design, selectors, middleware, SSR, and testing.

  • Refactoring Zustand stores
  • SKILL.md covers State Ownership, Store Design, Component Usage & Performance and TypeScript, plus 5 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md
  • Deciding whether state belongs in Zustand vs component state vs a server-state library

What it does

Zustand State Management is an agent skill from Mindrally/skills. Best practices for Zustand state management in React and TypeScript applications, covering store design, selectors, middleware, SSR, and testing. Use when creating or refactoring Zustand stores, deciding whether state belongs in Zustand vs component state vs a server-state library, optimizing selector re-renders, adding persist/devtools/immer middleware, or handling Zustand with SSR/React Server Components.

Its SKILL.md is about 1.8k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Frontend & Design, covering State management. It works with Zustand, React and TypeScript. The repository describes itself as: 265+ Claude Code skills for every major framework and language. Install with: npx skills add Mindrally/skills. The licence is Apache-2.0.

When your agent uses it

  • Refactoring Zustand stores
  • Deciding whether state belongs in Zustand vs component state vs a server-state library
  • Optimizing selector re-renders
  • Adding persist/devtools/immer middleware

Example prompts

  • “/zustand-state-management”

What it can do on your machine

Read from SKILL.md and the folder at commit 7682ca7. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are typescript).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Zustand State Management loads about 1.8k tokens when it runs. Until then it costs about 109 tokens; SKILL.md has 737 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~109
When it runs · the whole SKILL.md, loaded when a task matches
~1.8k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from Mindrally/skills at commit 7682ca7, republished under its Apache-2.0 licence (© Mindrally). 737 words, ~1,823 tokens.

Download SKILL.mdSave it as .claude/skills/zustand-state-management/SKILL.md (or your agent's skills folder).
name
zustand-state-management
description
Best practices for Zustand state management in React and TypeScript applications, covering store design, selectors, middleware, SSR, and testing. Use when creating or refactoring Zustand stores, deciding whether state belongs in Zustand vs component state vs a server-state library, optimizing selector re-renders, adding persist/devtools/immer middleware, or handling Zustand with SSR/React Server Components.
metadata.maintainer
Mindrally
metadata.source
https://github.com/Mindrally/skills

Zustand State Management

This skill covers designing and using Zustand stores in React and TypeScript applications, including state ownership decisions, store slicing, selector performance, middleware, SSR, and testing.

State Ownership

  • Keep ephemeral UI state in the nearest component with useState or useReducer — don't reach for Zustand by default.
  • Use URL state for shareable filters, pagination, tabs, and search params.
  • Use Zustand only for client state that is genuinely shared across unrelated components (auth session view state, command palette, cart draft, editor state, etc.).
  • Use TanStack Query, SWR, RTK Query, or the project's existing data layer for server state — don't duplicate fetched server data into a Zustand store unless there's a documented offline or draft-editing requirement.
  • Implement functional, declarative patterns; avoid classes. Use descriptive variable names with auxiliary verbs like isLoading, hasError.

Store Design

  • Model each store as state plus named actions; avoid exposing anonymous setters for component code to misuse.
  • Keep stores small and domain-focused rather than one global store for the entire application.
  • Split large stores into typed slices, then apply middleware only at the composed store boundary.
  • Keep derived values as selectors or small pure helpers unless they must be cached in state.
  • Store serializable data by default; keep DOM nodes, promises, sockets, and timers outside store state.
typescript
import { create } from 'zustand'

interface SidebarState {
  isOpen: boolean
  activePanelId: string | null
}

interface SidebarActions {
  openPanel: (panelId: string) => void
  close: () => void
  toggle: () => void
}

type SidebarStore = SidebarState & SidebarActions

export const useSidebarStore = create<SidebarStore>()((set) => ({
  isOpen: false,
  activePanelId: null,
  openPanel: (panelId) => set({ isOpen: true, activePanelId: panelId }),
  close: () => set({ isOpen: false, activePanelId: null }),
  toggle: () => set((state) => ({ isOpen: !state.isOpen })),
}))

Component Usage & Performance

  • Subscribe to the smallest possible slice: useStore((state) => state.value). Avoid selecting the entire store.
  • Do not call a store hook without a selector in components unless the component truly needs every field.
  • Use useShallow (from zustand/react/shallow) when a selector returns an object or tuple of multiple values, to avoid re-renders from a new object reference each call.
  • Keep selectors pure and cheap; move expensive derivations into memoized helpers.
tsx
import { useShallow } from 'zustand/react/shallow'
import { useSidebarStore } from '@/stores/sidebar-store'

export function SidebarToggle() {
  const { isOpen, toggle } = useSidebarStore(
    useShallow((state) => ({
      isOpen: state.isOpen,
      toggle: state.toggle,
    })),
  )

  return (
    <button type="button" aria-expanded={isOpen} onClick={toggle}>
      Toggle sidebar
    </button>
  )
}

TypeScript

  • Define explicit state and action interfaces for shared stores; combine them (type Store = State & Actions) rather than one flat interface for non-trivial stores.
  • Avoid any; use unknown plus narrowing for external data.
  • Type action payloads and return values, including async actions.
  • Prefer discriminated unions for complex local status instead of several loosely related booleans.
  • Export store state types when tests, utilities, or vanilla store factories need them.

Middleware

Updates
  • Use functional set((state) => nextState) when the next value depends on current state.
  • Treat nested state immutably; install and use the immer middleware only when it materially simplifies nested updates — don't mutate nested objects directly without it.
Persistence
typescript
import { persist } from 'zustand/middleware'

const useStore = create(
  persist(
    (set) => ({
      // state and actions
    }),
    { name: 'store-key' }
  )
)
  • Use persist only for state that must survive reloads.
  • Use partialize, version, and migrate when persisting anything beyond trivial preferences.
  • Never persist secrets, access tokens, refresh tokens, raw PII, or other long-lived authorization state to browser storage.
DevTools
typescript
import { devtools } from 'zustand/middleware'

const useStore = create(
  devtools((set) => ({
    // state and actions
  }))
)
  • Use devtools in development for complex flows and give important actions clear names so they're identifiable in the trace.
Show full SKILL.md (293 more words)Show less
Non-React Subscriptions
  • Use subscribeWithSelector for non-React subscriptions that need fine-grained updates outside of component rendering.

Async Actions & Error Handling

  • Async store actions should coordinate client-only workflows, optimistic drafts, or local device APIs — keep HTTP fetching in the project's server-state layer unless the state is explicitly client-owned.
  • Represent async client workflows with explicit statuses such as idle, pending, success, and error rather than ad hoc booleans.
  • Handle errors at function start using early returns and guard clauses; use try-catch in async actions and provide meaningful error messages.
  • Reset error state deliberately when retrying or closing a workflow.

SSR and React Server Components

  • Do not read or mutate browser-only stores from React Server Components.
  • In SSR frameworks (Next.js App Router, etc.), create per-request vanilla stores when state must be initialized on the server, rather than a shared module-level store.
  • Guard persisted stores against hydration mismatches before rendering storage-backed values.
  • Keep store modules free of direct window, document, and storage access outside middleware configuration.

Testing

  • Test stores independently of components — test store actions directly without rendering React when possible.
  • Reset stores between tests with their initial state.
  • Assert selectors and actions separately from component behavior; mock Zustand stores in component tests when isolating UI logic.
  • Mock server-state libraries instead of routing fetched data through Zustand for tests.
  • Test middleware behavior (persistence, devtools) separately from core store logic.

Anti-Patterns

  • Do not create one global store for the entire application.
  • Do not put form input state in Zustand unless multiple distant components edit the same draft.
  • Do not mutate nested objects directly without Immer middleware.
  • Do not use Zustand as an event bus; prefer explicit callbacks, services, or a scoped store.
  • Do not introduce Redux-style reducers, action constants, or dispatch wrappers unless the project already uses that pattern.

© Mindrally, Apache-2.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in zustand-state-management of Mindrally/skills.

Open the folder on GitHubat commit 7682ca7

Compare with similar skills

Zustand State Management next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Zustand State Management compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Zustand State Management this skillMindrally/skills271—~1.8kAutomated safety check: PassApache-2.0
React ExpertJeffallan/claude-skills12k—~1.4kAutomated safety check: PassMIT
React Flow Node TSmicrosoft/skills3.1k6 repos~502Automated safety check: PassMIT
React Generate Skilljiushiwon/wg-skills114—~2.8kAutomated safety check: PassApache-2.0
Zustand State Managementsecondsky/claude-skills227—~2.5kAutomated safety check: PassMIT
Dify Component Writing Guidelanggenius/dify158k—~626Automated safety check: PassCustom licence

Similar skills

  • React Expert

    Jeffallan/claude-skills

    Builds React 19 components in TypeScript with Server Components, useActionState forms, custom hooks and state libraries, checked with tsc and React Testing Library.

    12k GitHub stars~1.4k tokensUpdated 7 days ago
    Frontend & DesignAuto-check passed
  • React Flow Node TS

    microsoft/skills

    Official

    Create React Flow node components with TypeScript types, handles, and Zustand integration.

    3.1k GitHub starsUsed in 6 repos~502 tokens
    Frontend & DesignAuto-check passed
  • React Generate Skill

    jiushiwon/wg-skills

    This skill should be used when the user wants to create a standardized React 18 + TypeScript + Vite + Zustand project from scratch.

    114 GitHub stars~2.8k tokensUpdated 4 days ago
    Frontend & DesignAuto-check passed
  • Zustand State Management

    secondsky/claude-skills

    Zustand state management for React with TypeScript. An agent skill from secondsky/claude-skills.

    227 GitHub stars~2.5k tokensUpdated 13 days ago
    Frontend & DesignAuto-check passed
  • Use when implementing or refactoring React/TypeScript components and the task requires decisions about component ownership, feature boundaries, state, data…

    158k GitHub stars~626 tokensUpdated today
    Frontend & DesignAuto-check passed
  • Explains how LobeHub client code fetches data through services, SWR store hooks and cache keys, and when to avoid useEffect fetching or duplicated state.

    83k GitHub stars~1.8k tokensUpdated today
    Frontend & DesignAuto-check passed

More from Mindrally/skills

All 34 skills in this repo
  • Analytics Data Analysis

    Mindrally/skills

    Best practices for analytics, data analysis, and visualization using Python, pandas, matplotlib, seaborn, and Jupyter notebooks.

    271 GitHub stars~1.6k tokensUpdated 2 days ago
    Auto-check passed
  • Best practices for AutoML and hyperparameter search with Optuna, Ray Tune, and PyCaret, covering search-space design, validation splits, and leakage prevention.

    271 GitHub stars~2.5k tokensUpdated 2 days ago
    Auto-check passed
  • Blender Python Addon

    Mindrally/skills

    Best practices for writing Blender Python add-ons using the bpy API, covering operators, panels, properties, registration, and API-safe scripting.

    271 GitHub stars~2.2k tokensUpdated 2 days ago
    Auto-check passed
  • Expert guidelines for Chrome extension development with Manifest V3, covering security, performance, and best practices.

    271 GitHub stars~1.7k tokensUpdated 2 days ago
    Auto-check passed
  • Clean Code

    Mindrally/skills

    Clean, maintainable, human-readable code principles combined with anti-over-engineering discipline: naming, single responsibility, DRY, and scoping changes to exactly what was requested.

    271 GitHub stars~1.8k tokensUpdated 2 days ago
    Auto-check passed
  • Design Systems

    Mindrally/skills

    Comprehensive design system guidelines for building consistent, accessible, and scalable component libraries.

    271 GitHub stars~1.8k tokensUpdated 2 days ago
    Auto-check passed

Questions about Zustand State Management

What does Zustand State Management do?

Best practices for Zustand state management in React and TypeScript applications, covering store design, selectors, middleware, SSR, and testing. Zustand State Management is an agent skill from Mindrally/skills. Best practices for Zustand state management in React and TypeScript applications, covering store design, selectors, middleware, SSR, and testing.

When should I use Zustand State Management?

Zustand State Management fits situations like: refactoring Zustand stores; deciding whether state belongs in Zustand vs component state vs a server-state library; optimizing selector re-renders; adding persist/devtools/immer middleware.

How do I install Zustand State Management in Claude Code?

Run `npx skills add Mindrally/skills --skill zustand-state-management -a claude-code`. Or copy the skill folder (zustand-state-management in Mindrally/skills) into .claude/skills/zustand-state-management in your project. Claude Code loads it when a task matches its description.

How do I install Zustand State Management in Codex?

Run `npx skills add Mindrally/skills --skill zustand-state-management -a codex`. Or copy the skill folder (zustand-state-management in Mindrally/skills) into .agents/skills/zustand-state-management in your project. Codex loads it when a task matches its description.

Can I use Zustand State Management in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add Mindrally/skills --skill zustand-state-management -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/zustand-state-management, .gemini/skills/zustand-state-management, .github/skills/zustand-state-management and .opencode/skills/zustand-state-management in your project.

What does Zustand State Management need to run?

SKILL.md names no scripts, command-line tools or credentials: Zustand State Management is instructions for the agent only.

Does Zustand State Management access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Zustand State Management safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Zustand State Management use?

Zustand State Management is published under the Apache-2.0 licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Zustand State Management use?

About 1.8k tokens (SKILL.md is roughly 7.3k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Zustand State Management?

Skills that share tags, products or a category with Zustand State Management: React Expert (Jeffallan/claude-skills, 12k stars), React Flow Node TS (microsoft/skills, 3.1k stars), React Generate Skill (jiushiwon/wg-skills, 114 stars) and Zustand State Management (secondsky/claude-skills, 227 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Zustand State Management?

Mindrally (a GitHub organization) maintains it in Mindrally/skills, which has 271 GitHub stars. The repository holds 34 skills in this directory. The repository was last updated on October 8, 2026.

Source: Mindrally/skills on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.