Loading...
Loading...
Zustand v5 state management for Next.js 16 App Router. Use when implementing global state, stores, persist, hydration, or client-side state in Client Components.
npx skill4agent add fusengine/agents nextjs-zustandTeamCreate| 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/modules/cores/stores/modules/auth/src/stores/modules/cart/src/stores/modules/[feature]/src/interfaces/| File | Purpose | Max Lines |
|---|---|---|
| Store creation with create() | 50 |
| TypeScript interfaces | 30 |
| Context provider (App Router) | 40 |
| Custom hook with selector | 20 |
createStorezustand/vanillauseRefskipHydration: true| 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)| 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 | |
| v4 syntax | TypeScript inference broken | v5 currying |