#601

Global Rank · of 601 Skills

zustand AI Agent Skill

View Source: oakoss/agent-skills

Safe

Installation

npx skills add oakoss/agent-skills --skill zustand

45

Installs

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

Installs

Installs 45
Global Rank #601 of 601

Security Audit

ath Safe
socket Safe
Alerts: 0 Score: 90
snyk Low
zeroleaks Safe
Score: 93
EU EU-Hosted Inference API

Power your AI Agents with the best open-source models.

Drop-in OpenAI-compatible API. No data leaves Europe.

Explore Inference API

GLM

GLM 5

$1.00 / $3.20

per M tokens

Kimi

Kimi K2.5

$0.60 / $2.80

per M tokens

MiniMax

MiniMax M2.5

$0.30 / $1.20

per M tokens

Qwen

Qwen3.5 122B

$0.40 / $3.00

per M tokens

How to use this skill

1

Install zustand by running npx skills add oakoss/agent-skills --skill zustand in your project directory. Run the install command above in your project directory. The skill file will be downloaded from GitHub and placed in your project.

2

No configuration needed. Your AI agent (Claude Code, Cursor, Windsurf, etc.) automatically detects installed skills and uses them as context when generating code.

3

The skill enhances your agent's understanding of zustand, helping it follow established patterns, avoid common mistakes, and produce production-ready output.

What you get

Skills are plain-text instruction files — not executable code. They encode expert knowledge about frameworks, languages, or tools that your AI agent reads to improve its output. This means zero runtime overhead, no dependency conflicts, and full transparency: you can read and review every instruction before installing.

Compatibility

This skill works with any AI coding agent that supports the skills.sh format, including Claude Code (Anthropic), Cursor, Windsurf, Cline, Aider, and other tools that read project-level context files. Skills are framework-agnostic at the transport level — the content inside determines which language or framework it applies to.

Data sourced from the skills.sh registry and GitHub. Install counts and security audits are updated regularly.

EU Made in Europe

Chat with 100+ AI Models in one App.

Use Claude, ChatGPT, Gemini alongside with EU-Hosted Models like Deepseek, GLM-5, Kimi K2.5 and many more.

Customer Support