zustand

Implements Zustand 5 state management patterns with selectors, persistence, and modular slices.

1|Updated Jul 18, 2025
One-click install
npx skills add https://github.com/AdelysAlberto/md-configs-and-agents --skill zustand-adelysalberto
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: zustand
Source: https://github.com/AdelysAlberto/md-configs-and-agents/tree/main/agents-copilot/skills/zustand
Command: npx skills add https://github.com/AdelysAlberto/md-configs-and-agents --skill zustand-adelysalberto

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires zustand.

What problem does it solve? Managing client-side state in React applications often leads to infinite render loops, unnecessary re-renders, and insecure data persistence. This Skill provides proven Zustand 5 patterns that prevent these issues while keeping state logic functional and predictable. ## Core Features & Use Cases - Re-render Prevention: Enforces atomic selectors and useShallow to eliminate infinite loops and wasted renders caused by unstable object references. - Secure Persistence: Guides session-isolated storage using sessionStorage and partialize to avoid leaking user data through localStorage. - Modular Architecture: Demonstrates the slice pattern for combining independent state domains into a single typed root store, plus async actions with explicit error handling. - Use Case: When building a multi-step checkout wizard, use this Skill to create a persisted store that survives refreshes within the tab session, resets cleanly on completion, and never triggers "Maximum update depth exceeded" errors. ## Quick Start Create a Zustand store for my shopping cart with add, remove, and reset actions following best practices.

Frequently Asked Questions about zustand

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent infinite render loops in Zustand?▼

Infinite loops in Zustand happen when a selector returns a new object or array reference on every render. Fix this by selecting values individually with atomic selectors, or wrap multi-property selectors in useShallow from zustand/react/shallow.

How to persist Zustand state securely across page refreshes?▼

Use the persist middleware with createJSONStorage pointing to sessionStorage instead of localStorage to isolate data per tab. Combine it with partialize to persist only the fields you actually need, avoiding token or session leaks between users.

Should I use Zustand or TanStack Query for API data?▼

Use TanStack Query for server data since it handles fetching, caching, synchronization, and invalidation automatically. Reserve Zustand for client and UI state such as modals, wizards, active filters, and sidebar preferences.

Can I access Zustand state outside React components?▼

Yes, Zustand stores work outside React. Call useStore.getState() to read current values or dispatch actions, and useStore.subscribe() to listen for changes inside services or network interceptors without hooks.

How do I split a large Zustand store into slices?▼

Define each domain as a separate slice using StateCreator with typed generics, then merge them into one root store by spreading each slice creator. This keeps large modules independent while sharing a single typed store.