askill
zustand

zustandSafety 95Repository

Implement global state management for React/TypeScript applications. Use when creating, modifying, or debugging Zustand stores, implementing state management patterns (slices, persist, devtools, immer), setting up Zustand with Next.js/SSR, writing tests for Zustand stores, or working with TypeScript typing for Zustand (curried create, StateCreator, middleware mutators).

1 stars
1.2k downloads
Updated 2/20/2026

Package Files

Loading files...
SKILL.md

Zustand

Lightweight state management for React. No providers, no boilerplate. Stores are hooks.

Quick start

import { create } from "zustand"

interface BearState {
  bears: number
  increase: (by: number) => void
}

const useBearStore = create<BearState>()((set) => ({
  bears: 0,
  increase: (by) => set((state) => ({ bears: state.bears + by })),
}))

// In components — select only what you need
const bears = useBearStore((state) => state.bears)

Critical rules

  1. TypeScript: Use curried form create<T>()(...) — required for type inference
  2. Immutability: Treat state as immutable. set shallow-merges at one level only
  3. Selectors: Always select specific fields, not the whole store. Use useShallow for multi-field selectors returning new references
  4. Middleware order: devtools must be outermost: devtools(persist(immer(...)))
  5. Next.js: Create stores per-request via createStore + Context, NOT global create
  6. Nested updates: Use Immer for deep nesting, spread operator for shallow

When to use what

NeedSolution
Basic React storecreate<T>()(...)
Vanilla (non-React) storecreateStore from zustand/vanilla
Use vanilla store in ReactuseStore(store, selector)
Auto-infer types (no interface)combine middleware
Persist to localStoragepersist middleware
Redux DevToolsdevtools middleware
Mutable-style updatesimmer middleware
Subscribe to slices externallysubscribeWithSelector middleware
Multiple fields without rerenderuseShallow wrapper
Large store modularizationSlices pattern with StateCreator
Next.js App RoutercreateStore + Context + Provider
Reset storeset(initialState) or store.getInitialState()

References

Install

Download ZIP
Requires askill CLI v1.0+

AI Quality Score

81/100Analyzed 2/24/2026

High-quality Zustand reference skill with clear quick start, critical rules, and helpful lookup table. Well-structured for reusability with API tag. Scores well on safety and clarity. Minor gaps in detailed examples for testing/Next.js but references external docs for deeper coverage.

95
85
80
75
70

Metadata

Licenseunknown
Version-
Updated2/20/2026
Publisherfellipeutaka

Tags

api