Skills DirectorySkills Directory
SkillsLearnSecurityCategoriesDocsBlogPro
Sign InSubmit Skill
Skills Directory

Security-tested agent skills for Claude, coding agents, and AI workflows.

Directory

  • Browse Skills
  • All Skills A–Z
  • Claude Skills
  • Claude Code Skills
  • Agent Skills
  • Categories
  • Authors
  • Submit a Skill

Learn

  • Learn Hub
  • Install Claude Skills
  • Write SKILL.md
  • Skills vs MCP
  • Directories Compared

Security

  • Security
  • Methodology
  • Secure Claude Skills
  • Security Badges
  • Chrome Extension
  • Skill Manager

Company

  • About
  • Community
  • Blog
  • API Docs
  • Advertise

2026 Skills Directory. All rights reserved.

ProTermsPrivacyRefunds
Back to skills

Zustand Pro

ASecurity

Manage client state with Zustand: stores, slices, selectors, middleware, and async actions. Use for lightweight React state without boilerplate.

2 stars
0 votes
0 copies
0 views
Added 9/29/2026
ai-agentsgoreactdebuggingapi

Works with

cliapi

Security Analysis

A100/100

Scanned 9/29/2026

$npx -y skills add aicodedecode/awesome-muse-skills --skill zustand-pro --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Zustand Pro?

Add the live security badge to your README — it updates automatically with every re-scan.

Security grade badge for Zustand Pro
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/aicodedecode-zustand-pro/badge)](https://www.skillsdirectory.com/skills/aicodedecode-zustand-pro)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
Files
SKILL.md
---
name: zustand-pro
description: Manage client state with Zustand: stores, slices, selectors, middleware, and async actions. Use for lightweight React state without boilerplate.
category: development
---

# Zustand Pro

A practical guide to Zustand: minimal, hook-based React state management — store creation, selector subscriptions, slices, middleware (persist, devtools, immer), and async actions — without boilerplate.

## Overview

Zustand is a tiny store with a simple contract: `create(set => ({...}))` gives you a hook. Components subscribe to **slices** via selectors and re-render only when their slice changes. No providers (usually), no reducers, no ceremony. It's the right default for client state (UI state, auth session, feature flags, form drafts) in most React apps — reach for Redux only when you need its ecosystem or strict conventions at scale.

## When to use

- Client/UI state: modals, toasts, theme, sidebar, auth user.
- Replacing prop drilling or Context for frequently-updated state.
- Persisting state to localStorage (persist middleware).
- Async flows in the store (fetch + set, with loading states).
- Apps where Redux feels like overkill.

## Core concepts

- **Store.** `const useStore = create<State>()((set, get) => ({ count: 0, inc: () => set(s => ({ count: s.count + 1 })) }))`. Actions live next to state.
- **Selectors.** `const count = useStore(s => s.count)` — component re-renders only when `count` changes. Select the minimum you need.
- **`get()`.** Read current state inside actions without subscribing: `set({ items: [...get().items, newItem] })`.
- **Slices pattern.** Split large stores: `create<BearSlice & FishSlice>()((...a) => ({ ...createBearSlice(...a), ...createFishSlice(...a) }))` — keeps files focused.
- **Middleware.** `devtools` (Redux DevTools integration), `persist` (localStorage/sessionStorage with versioning + migration), `immer` (mutative-style updates), `subscribeWithSelector`.
- **Transient updates.** `useStore.subscribe` or refs for high-frequency values (scroll position, mouse) that shouldn't re-render.
- **Outside React.** `useStore.getState()` works anywhere — event handlers, utilities, non-React code.

## Practical workflow

**1. Create a focused store.**
```ts
import { create } from 'zustand';
import { devtools, persist } from 'zustand/middleware';

type AuthState = {
  user: User | null;
  login: (user: User) => void;
  logout: () => void;
};

export const useAuth = create<AuthState>()(
  devtools(
    persist(
      (set) => ({
        user: null,
        login: (user) => set({ user }, false, 'auth/login'),
        logout: () => set({ user: null }, false, 'auth/logout'),
      }),
      { name: 'auth-storage', version: 1 }
    ),
    { name: 'auth' }
  )
);
```

**2. Subscribe narrowly.**
```tsx
const user = useAuth(s => s.user);        // re-renders only when user changes
const login = useAuth(s => s.login);      // stable reference, never re-renders
```
Returning objects from selectors re-renders every time unless shallow-compared — use `useShallow` for multi-field selection.

**3. Async actions.**
```ts
fetchUser: async (id) => {
  set({ status: 'loading' });
  try { const user = await api.getUser(id); set({ user, status: 'idle' }); }
  catch (e) { set({ error: String(e), status: 'idle' }); }
},
```

**4. Persist with migrations.** `persist` options: `version`, `migrate: (state, version) => ...`, `partialize` to persist only part of the state (never persist tokens you shouldn't — or encrypt them).

## Common pitfalls

- **Selecting too much.** `useStore(s => s)` re-renders on any change — defeats the purpose. Select fields; `useShallow` for objects.
- **Object/array literals in selectors.** `useStore(s => ({ a: s.a }))` creates a new object each call → infinite re-renders. Wrap with `useShallow`.
- **Server state in Zustand.** Caching API responses here duplicates React Query's job and goes stale. Zustand = client state; server state = query cache.
- **Persisting secrets.** `persist` writes to localStorage — readable by any script on the page. Don't persist tokens/secrets; keep them in memory (or httpOnly cookies).
- **One giant store.** A 500-line store with everything is a context-blob in disguise. Split by domain (auth, ui, cart).
- **Mutating state.** `set` merges shallowly; nested updates need spreading or the immer middleware. Direct mutation silently breaks change detection.
- **Actions in render.** Calling `set` during render (not in an event/effect) → loops. Actions belong in handlers and effects.
- **No devtools in dev.** Add the `devtools` middleware early — time-travel debugging pays for itself the first hard bug.

Attribution

aicodedecodeaicodedecode
View sourceSee grades on GitHubMore from aicodedecode →
SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments (0)

No comments yet. Be the first to comment!

SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Related Skills

Caveman

Terse caveman voice: answer first, fluff gone, every technical fact kept. Use for /caveman, "caveman mode", "talk like caveman", "be brief", "less tokens". Stays on until "stop caveman" or "normal mode".

1100021 votes

Hyperplan

Adversarial multi-agent planning skill. Self-orchestrates 5 hostile category members (unspecified-low, unspecified-high, deep, ultrabrain, artistry) via team-mode for ruthless cross-critique debate, distills only the defensible insights, then MANDATORILY hands the distilled insight bundle to the `plan` agent for executable plan formalization. Use when planning needs maximum rigor and surfacing of weak assumptions, blind spots, and over-engineering. Triggers: 'hyperplan', 'hpp', '/hyperplan', ...

698461 votes

Writing Skills

Create and manage Claude Code skills in HASH repository following Anthropic best practices. Use when creating new skills, modifying skill-rules.json, understanding trigger patterns, working with hooks, debugging skill activation, or implementing progressive disclosure. Covers skill structure, YAML frontmatter, trigger types (keywords, intent patterns), UserPromptSubmit hook, and the 500-line rule. Includes validation and debugging with SKILL_DEBUG. Examples include rust-error-stack, cargo-dep...

3931 votes

Mcp Code Execution

Routes multi-tool workflows through MCP servers for large datasets and pipelines. Use when Bash tool overhead is limiting throughput on data-heavy tasks.

3421 votes

catchup

Recovers the conversation and failed tool calls of a previous Codex, Amp, Claude Code, Antigravity, Cline, Copilot CLI, Cursor, DeepSeek Harness, Grok Build, Kimi, OpenCode, Pi Agent, or ZCode session. Use when the user says "catch up", "what did the last session do", "get me up to speed", "I switched agents", asks to recover/summarize a previous session before continuing, or asks to diagnose or report a catchup failure. Do NOT use for the current conversation, git history, or any non-agent log.

741 votes
View all in ai-agents →