zustand-patterns — for Claude Code zustand-patterns, som-brain-turbo, community, for Claude Code, ide skills, Zustand, Patterns, Modern, management, lightweight

v1.0.0

About this Skill

Perfect for Frontend Agents needing lightweight state management with TypeScript support. Zustand 5.x state management with slices, middleware, Immer, useShallow, and persistence patterns for React applications. Use when building state management with Zustand.

Features

Modern state management with Zustand 5.x - lightweight, TypeScript-first, no boilerplate.
Global state without Redux complexity
Shared state across components without prop drilling
Persisted state with localStorage/sessionStorage
Computed/derived state with selectors

# Core Topics

OmarHosamCodes OmarHosamCodes
[0]
[0]
Updated: 3/2/2026

Killer-Skills Review

Decision support comes first. Repository text comes second.

Reviewed Landing Page Review Score: 10/11

Killer-Skills keeps this page indexable because it adds recommendation, limitations, and review signals beyond the upstream repository text.

Original recommendation layer Concrete use-case guidance Explicit limitations and caution Quality floor passed for review Locale and body language aligned
Review Score
10/11
Quality Score
52
Canonical Locale
en
Detected Body Locale
en

Perfect for Frontend Agents needing lightweight state management with TypeScript support. Zustand 5.x state management with slices, middleware, Immer, useShallow, and persistence patterns for React applications. Use when building state management with Zustand.

Core Value

Empowers agents to manage global state without Redux complexity, utilizing Zustand 5.x for shared state across components, persisted state with localStorage/sessionStorage, and computed/derived state with selectors.

Ideal Agent Persona

Perfect for Frontend Agents needing lightweight state management with TypeScript support.

Capabilities Granted for zustand-patterns

Managing global state across components
Implementing persisted state with localStorage/sessionStorage
Creating computed/derived state with selectors

! Prerequisites & Limits

  • Requires Zustand 5.x
  • TypeScript-first approach may require additional setup for non-TypeScript projects

Source Boundary

The section below is imported from the upstream repository and should be treated as secondary evidence. Use the Killer-Skills review above as the primary layer for fit, risk, and installation decisions.

After The Review

Decide The Next Action Before You Keep Reading Repository Material

Killer-Skills should not stop at opening repository instructions. It should help you decide whether to install this skill, when to cross-check against trusted collections, and when to move into workflow rollout.

Labs Demo

Browser Sandbox Environment

⚡️ Ready to unleash?

Experience this Agent in a zero-setup browser environment powered by WebContainers. No installation required.

Boot Container Sandbox

FAQ & Installation Steps

These questions and steps mirror the structured data on this page for better search understanding.

? Frequently Asked Questions

What is zustand-patterns?

Perfect for Frontend Agents needing lightweight state management with TypeScript support. Zustand 5.x state management with slices, middleware, Immer, useShallow, and persistence patterns for React applications. Use when building state management with Zustand.

How do I install zustand-patterns?

Run the command: npx killer-skills add OmarHosamCodes/som-brain-turbo/zustand-patterns. It works with Cursor, Windsurf, VS Code, Claude Code, and 19+ other IDEs.

What are the use cases for zustand-patterns?

Key use cases include: Managing global state across components, Implementing persisted state with localStorage/sessionStorage, Creating computed/derived state with selectors.

Which IDEs are compatible with zustand-patterns?

This skill is compatible with Cursor, Windsurf, VS Code, Trae, Claude Code, OpenClaw, Aider, Codex, OpenCode, Goose, Cline, Roo Code, Kiro, Augment Code, Continue, GitHub Copilot, Sourcegraph Cody, and Amazon Q Developer. Use the Killer-Skills CLI for universal one-command installation.

Are there any limitations for zustand-patterns?

Requires Zustand 5.x. TypeScript-first approach may require additional setup for non-TypeScript projects.

How To Install

  1. 1. Open your terminal

    Open the terminal or command line in your project directory.

  2. 2. Run the install command

    Run: npx killer-skills add OmarHosamCodes/som-brain-turbo/zustand-patterns. The CLI will automatically detect your IDE or AI agent and configure the skill.

  3. 3. Start using the skill

    The skill is now active. Your AI agent can use zustand-patterns immediately in the current project.

Upstream Repository Material

The section below is imported from the upstream repository and should be treated as secondary evidence. Use the Killer-Skills review above as the primary layer for fit, risk, and installation decisions.

Upstream Source

zustand-patterns

Install zustand-patterns, an AI agent skill for AI agent workflows and automation. Review the use cases, limitations, and setup path before rollout.

SKILL.md
Readonly
Upstream Repository Material
The section below is imported from the upstream repository and should be treated as secondary evidence. Use the Killer-Skills review above as the primary layer for fit, risk, and installation decisions.
Supporting Evidence

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)

Core Patterns

1. Basic Store with TypeScript

typescript
1import { create } from 'zustand'; 2 3interface BearState { 4 bears: number; 5 increase: (by: number) => void; 6 reset: () => void; 7} 8 9const useBearStore = create<BearState>()((set) => ({ 10 bears: 0, 11 increase: (by) => set((state) => ({ bears: state.bears + by })), 12 reset: () => set({ bears: 0 }), 13}));

2. Slices Pattern (Modular Stores)

typescript
1import { create, StateCreator } from 'zustand'; 2 3// Auth slice 4interface AuthSlice { 5 user: User | null; 6 login: (user: User) => void; 7 logout: () => void; 8} 9 10const createAuthSlice: StateCreator<AuthSlice & CartSlice, [], [], AuthSlice> = (set) => ({ 11 user: null, 12 login: (user) => set({ user }), 13 logout: () => set({ user: null }), 14}); 15 16// Cart slice 17interface CartSlice { 18 items: CartItem[]; 19 addItem: (item: CartItem) => void; 20 clearCart: () => void; 21} 22 23const createCartSlice: StateCreator<AuthSlice & CartSlice, [], [], CartSlice> = (set) => ({ 24 items: [], 25 addItem: (item) => set((state) => ({ items: [...state.items, item] })), 26 clearCart: () => set({ items: [] }), 27}); 28 29// Combined store 30const useStore = create<AuthSlice & CartSlice>()((...a) => ({ 31 ...createAuthSlice(...a), 32 ...createCartSlice(...a), 33}));

3. Immer Middleware (Immutable Updates)

typescript
1import { create } from 'zustand'; 2import { immer } from 'zustand/middleware/immer'; 3 4interface TodoState { 5 todos: Todo[]; 6 addTodo: (text: string) => void; 7 toggleTodo: (id: string) => void; 8 updateNested: (id: string, subtaskId: string, done: boolean) => void; 9} 10 11const useTodoStore = create<TodoState>()( 12 immer((set) => ({ 13 todos: [], 14 addTodo: (text) => 15 set((state) => { 16 state.todos.push({ id: crypto.randomUUID(), text, done: false }); 17 }), 18 toggleTodo: (id) => 19 set((state) => { 20 const todo = state.todos.find((t) => t.id === id); 21 if (todo) todo.done = !todo.done; 22 }), 23 updateNested: (id, subtaskId, done) => 24 set((state) => { 25 const todo = state.todos.find((t) => t.id === id); 26 const subtask = todo?.subtasks?.find((s) => s.id === subtaskId); 27 if (subtask) subtask.done = done; 28 }), 29 })) 30);

4. Persist Middleware

typescript
1import { create } from 'zustand'; 2import { persist, createJSONStorage } from 'zustand/middleware'; 3 4interface SettingsState { 5 theme: 'light' | 'dark'; 6 language: string; 7 setTheme: (theme: 'light' | 'dark') => void; 8} 9 10const useSettingsStore = create<SettingsState>()( 11 persist( 12 (set) => ({ 13 theme: 'light', 14 language: 'en', 15 setTheme: (theme) => set({ theme }), 16 }), 17 { 18 name: 'settings-storage', 19 storage: createJSONStorage(() => localStorage), 20 partialize: (state) => ({ theme: state.theme }), // Only persist theme 21 version: 1, 22 migrate: (persisted, version) => { 23 if (version === 0) { 24 // Migration logic 25 } 26 return persisted as SettingsState; 27 }, 28 } 29 ) 30);

5. Selectors (Prevent Re-renders)

typescript
1// ❌ BAD: Re-renders on ANY state change 2const { bears, fish } = useBearStore(); 3 4// ✅ GOOD: Only re-renders when bears changes 5const bears = useBearStore((state) => state.bears); 6 7// ✅ GOOD: Shallow comparison for objects (Zustand 5.x) 8import { useShallow } from 'zustand/react/shallow'; 9 10const { bears, fish } = useBearStore( 11 useShallow((state) => ({ bears: state.bears, fish: state.fish })) 12); 13 14// ✅ GOOD: Computed/derived state via selector 15const totalAnimals = useBearStore((state) => state.bears + state.fish); 16 17// ❌ BAD: Storing computed state 18const useStore = create((set) => ({ 19 items: [], 20 total: 0, // Don't store derived values! 21 addItem: (item) => set((s) => ({ 22 items: [...s.items, item], 23 total: s.total + item.price, // Sync issues! 24 })), 25})); 26 27// ✅ GOOD: Compute in selector 28const total = useStore((s) => s.items.reduce((sum, i) => sum + i.price, 0));

6. Async Actions

typescript
1interface UserState { 2 user: User | null; 3 loading: boolean; 4 error: string | null; 5 fetchUser: (id: string) => Promise<void>; 6} 7 8const useUserStore = create<UserState>()((set) => ({ 9 user: null, 10 loading: false, 11 error: null, 12 fetchUser: async (id) => { 13 set({ loading: true, error: null }); 14 try { 15 const user = await api.getUser(id); 16 set({ user, loading: false }); 17 } catch (error) { 18 set({ error: error.message, loading: false }); 19 } 20 }, 21}));

7. DevTools Integration

typescript
1import { create } from 'zustand'; 2import { devtools } from 'zustand/middleware'; 3 4const useStore = create<State>()( 5 devtools( 6 (set) => ({ 7 // ... state and actions 8 }), 9 { name: 'MyStore', enabled: process.env.NODE_ENV === 'development' } 10 ) 11);

Quick Reference

typescript
1// ✅ Create typed store with double-call pattern 2const useStore = create<State>()((set, get) => ({ ... })); 3 4// ✅ Use selectors for all state access 5const count = useStore((s) => s.count); 6 7// ✅ Use useShallow for multiple values (Zustand 5.x) 8const { a, b } = useStore(useShallow((s) => ({ a: s.a, b: s.b }))); 9 10// ✅ Middleware order: immer → subscribeWithSelector → devtools → persist 11create(persist(devtools(immer((set) => ({ ... }))))) 12 13// ❌ Never destructure entire store 14const store = useStore(); // Re-renders on ANY change 15 16// ❌ Never store server state (use TanStack Query instead) 17const useStore = create((set) => ({ users: [], fetchUsers: async () => ... }));

Key Decisions

DecisionOption AOption BRecommendation
State structureSingle storeMultiple storesSlices in single store - easier cross-slice access
Nested updatesSpread operatorImmer middlewareImmer for deeply nested state (3+ levels)
PersistenceManual localStoragepersist middlewarepersist middleware with partialize
Multiple valuesMultiple selectorsuseShallowuseShallow for 2-5 related values
Server stateZustandTanStack QueryTanStack Query - Zustand for client-only state
DevToolsAlways onConditionalConditional - enabled: process.env.NODE_ENV === 'development'

Anti-Patterns (FORBIDDEN)

typescript
1// ❌ FORBIDDEN: Destructuring entire store 2const { count, increment } = useStore(); // Re-renders on ANY state change 3 4// ❌ FORBIDDEN: Storing derived/computed state 5const useStore = create((set) => ({ 6 items: [], 7 total: 0, // Will get out of sync! 8})); 9 10// ❌ FORBIDDEN: Storing server state 11const useStore = create((set) => ({ 12 users: [], // Use TanStack Query instead 13 fetchUsers: async () => { ... }, 14})); 15 16// ❌ FORBIDDEN: Mutating state without Immer 17set((state) => { 18 state.items.push(item); // Breaks reactivity! 19 return state; 20}); 21 22// ❌ FORBIDDEN: Using deprecated shallow import 23import { shallow } from 'zustand/shallow'; // Use useShallow from zustand/react/shallow

Integration with React Query

typescript
1// ✅ Zustand for CLIENT state (UI, preferences, local-only) 2const useUIStore = create<UIState>()((set) => ({ 3 sidebarOpen: false, 4 theme: 'light', 5 toggleSidebar: () => set((s) => ({ sidebarOpen: !s.sidebarOpen })), 6})); 7 8// ✅ TanStack Query for SERVER state (API data) 9function Dashboard() { 10 const sidebarOpen = useUIStore((s) => s.sidebarOpen); 11 const { data: users } = useQuery({ queryKey: ['users'], queryFn: fetchUsers }); 12 // Zustand: UI state | TanStack Query: server data 13}
  • tanstack-query-advanced - Server state management (use with Zustand for client state)
  • form-state-patterns - Form state (React Hook Form vs Zustand for forms)
  • react-server-components-framework - RSC hydration considerations with Zustand

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 between versions

References

  • references/middleware-composition.md - Combining multiple middleware
  • scripts/store-template.ts - Production-ready store template
  • checklists/zustand-checklist.md - Implementation checklist

Related Skills

Looking for an alternative to zustand-patterns or another community skill for your workflow? Explore these related open-source skills.

View All

openclaw-release-maintainer

Logo of openclaw
openclaw

openclaw-release-maintainer is an AI agent skill for openclaw release maintainer.

333.8k
0
AI

widget-generator

Logo of f
f

Generate customizable widget plugins for the prompts.chat feed system

149.6k
0
AI

flags

Logo of vercel
vercel

flags is an AI agent skill for use this skill when adding or changing framework feature flags in next.js internals.

138.4k
0
Browser

pr-review

Logo of pytorch
pytorch

pr-review is an AI agent skill for pytorch pr review skill.

98.6k
0
Developer