zustand_state

Implements Zustand state management stores in React with TypeScript, persistence, and middleware patterns.

Updated Jan 14, 2026
One-click install
npx skills add https://github.com/jvsandhu/agentic-skills --skill zustand-state-jvsandhu
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: zustand_state
Source: https://github.com/jvsandhu/agentic-skills/tree/main/skills/zustand_state
Command: npx skills add https://github.com/jvsandhu/agentic-skills --skill zustand-state-jvsandhu

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires zustand, react, and includes scripts (resource) and references (resource) components.

What problem does it solve? Setting up Zustand correctly in React projects involves subtle pitfalls: TypeScript middleware typing breaks without the curried create<T>()() syntax, Next.js apps hit hydration mismatches with persisted state, and naive selectors cause infinite render loops. This Skill provides production-tested patterns that prevent these documented issues. ## Core Features & Use Cases - Typed Store Patterns: Three setup patterns (basic JavaScript, TypeScript, and persistent stores) with correct create<T>()() syntax and interface separation. - Middleware Configuration: Ready-made setups for persist (localStorage), devtools (Redux DevTools), immer, and custom middleware composition. - Issue Prevention: Documented fixes for five known issues including Next.js hydration mismatch, infinite render loops, and slices pattern typing. - Use Case: When building a Next.js app that needs user preferences persisted across reloads, apply the _hasHydrated flag pattern with the persist middleware to avoid SSR hydration errors. ## Quick Start Ask the agent to create a TypeScript Zustand store with persist middleware for your React project.

Frequently Asked Questions about zustand_state

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

FAQPage Schema
How do I create a Zustand store with TypeScript?

Define an interface for state and actions, then use the curried syntax create<YourStore>()((set) => ({ ... })). The double parentheses are required for middleware type inference to work correctly in TypeScript.

How to persist Zustand state to localStorage?

Wrap your store creator with the persist middleware from zustand/middleware and provide a unique storage name. Use createJSONStorage(() => localStorage) to explicitly configure the storage backend and partialize to select which fields persist.

Why does Zustand persist cause Next.js hydration errors?

Persist middleware reads localStorage only on the client, so server-rendered HTML mismatches the client state. Fix it with a _hasHydrated flag set via onRehydrateStorage, and render a loading state until hydration completes.

Why does my Zustand component re-render infinitely?

Returning a new object from a selector creates a new reference each render, triggering endless updates. Select primitives individually or pass the shallow comparator from zustand/shallow as the second argument.

When should I not use Zustand for state management?

Avoid Zustand for server state such as API data fetching and caching; use TanStack Query instead. Zustand is designed for client-side UI state, preferences, and local application state.