/fuse-nextjs:nextjs-zustandfrom fuse-nextjs
Implements Zustand v5 client-side state management in Next.js 16 App Router: Context-based stores, v5 currying syntax, middleware composition, skipHydration, and SOLID file organization.
Ships in fuse-nextjs. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Covers skipHydration with the persist middleware plus manual rehydration in useEffect to avoid SSR mismatches, useShallow for array/object selectors, and SOLID file organization (store.ts, store-provider.tsx, use-store.ts). States explicitly that Zustand is Client-Components-only — never used in Server Components (fetch data directly there instead) and never used to persist auth tokens (use httpOnly cookies). Does not cover server state caching (see nextjs-tanstack-query for that).
Minimal, scalable state management with React 18+ useSyncExternalStore.
Before ANY implementation, spawn 3 agents in parallel, one Agent call each with a name:
After implementation, run fuse-ai-pilot:sniper for validation.
| Feature | Benefit |
|---|---|
| Minimal API | Simple create() function, no boilerplate |
| React 18 native | useSyncExternalStore, no shims needed |
| TypeScript first | Full inference with currying pattern |
| Middleware stack | devtools, persist, immer composable |
| Bundle size | ~2KB gzipped, smallest state library |
| No providers | Direct store access, no Context wrapper |
create<State>()((set) => ({...}))modules/[feature]/src/stores/Stores organized by feature module:
modules/cores/stores/ - Shared stores (theme, ui)modules/auth/src/stores/ - Auth statemodules/cart/src/stores/ - Cart statemodules/[feature]/src/interfaces/ - Store types| File | Purpose |
|---|---|
store.ts | Store creation with create() (store budget 0.4 × FUSE_SOLID_MAX_LINES, 40 at default) |
store.interface.ts | TypeScript interfaces |
store-provider.tsx | Context provider (App Router) |
use-store.ts | Custom hook with selector |
Double parentheses required for TypeScript inference. Currying pattern ensures full type safety.
For Next.js App Router, wrap stores in Context to prevent request-sharing. Use createStore from zustand/vanilla with useRef for initialization.
Stack middlewares: devtools → persist → immer. Order matters for TypeScript types.
Use skipHydration: true with persist middleware. Manually rehydrate in useEffect to avoid SSR mismatches.
| Need | Reference |
|---|---|
| Initial setup | installation.md |
| Store patterns | store-patterns.md |
| SSR/Hydration | hydration.md |
| Middleware | middleware.md |
| Next.js App Router | nextjs-integration.md |
| TypeScript | typescript.md |
| Slices pattern | slices.md |
| Auto selectors | auto-selectors.md |
| Reset state | reset-state.md |
| Subscribe API | subscribe-api.md |
| Testing | testing.md |
| Migration v4→v5 | migration-v5.md |
useStore((s) => s.field) for performance| Pattern | Reason | Alternative |
|---|---|---|
| Global stores in App Router | Request sharing between users | Context-based stores |
| Zustand in Server Components | No React hooks in RSC | Fetch data directly |
| Persisting auth tokens | Security vulnerability | httpOnly cookies |
| Without useShallow on objects | Excessive re-renders | useShallow(selector) |
| v4 syntax | TypeScript inference broken | v5 currying create<T>()() |
references/auto-selectors.md (opens in a new tab)references/hydration.md (opens in a new tab)references/installation.md (opens in a new tab)references/middleware.md (opens in a new tab)references/migration-v5.md (opens in a new tab)references/nextjs-integration.md (opens in a new tab)references/reset-state.md (opens in a new tab)references/slices.md (opens in a new tab)references/store-patterns.md (opens in a new tab)references/subscribe-api.md (opens in a new tab)references/testing.md (opens in a new tab)references/typescript.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub fusengine/claude-plugins --plugin fuse-nextjs11 skills in this plugin
/better-authUse when implementing Next.js authentication with Better Auth — OAuth, 2FA, magic links, SSO, Stripe billing, or session management./nextjs-16Use when building Next.js 16 apps — Turbopack, App Router, Cache Components, proxy.ts, v15 migration. Not for stack scaffolding (nextjs-stack) or React SPA (react-expert)./nextjs-i18nUse when implementing i18n in Next.js 16 — next-intl or DIY dictionaries, locale routing, language switch, or formatters./nextjs-server-componentsUse when deciding Server vs Client Component boundaries in Next.js 16, fetching data directly in components, or streaming with Suspense./nextjs-shadcnUse when building UI components in Next.js App Router with shadcn/ui — forms, dialogs, tables, toasts, accessible components./nextjs-stackUse as the master reference for a full Next.js 16+ stack — Prisma 7, Better Auth, shadcn/ui, TanStack Form, Zustand. Not for core framework API details (use nextjs-16).Other plugins' skills for the same job