zustand

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).

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "zustand" with this command: npx skills add fellipeutaka/leon/fellipeutaka-leon-zustand

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

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Coding

clean-code

No summary provided by upstream source.

Repository SourceNeeds Review
General

docker

No summary provided by upstream source.

Repository SourceNeeds Review
General

commit-work

No summary provided by upstream source.

Repository SourceNeeds Review
General

motion

No summary provided by upstream source.

Repository SourceNeeds Review