zustand-state
БесплатноБез исполняемых скриптовНе проверенZustand v5 state management for React and vanilla TypeScript. Use when creating stores with curried create<T>()(...), preventing infinite selector re-renders…
от existential-birds★ 92 звезды на GitHubОб этом скилле
Zustand State Management (v5)
Minimal state management — named exports only (v5 removed default exports), React 18/19 compatible, and no global providers required.
Quick Reference
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 component - select only what you need
const bears = useBearStore((state) => state.bears)
const increase = useBearStore((state) => state.increase)
State Updates
// Flat updates (auto-merged at one level)
set({ bears: 5 })
set((state) => ({ bears: state.bears + 1 }))
// Nested objects (manual spread required without immer)
set((state) => ({
nested: { ...state.nested, count: state.nested.count + 1 }
}))
// Replace entire state (no merge)
set({ bears: 0 }, true)
Selectors & Performance (v5 useShallow)
In Zustand v5, base create no longer accepts a custom equality function as a 2nd argument. Returning a fresh object or array literal from a selector without useShallow causes infinite re-renders (Maximum update depth exceeded):
import { useShallow } from 'zustand/react/shallow'
// Good - subscribes only to bears
const bears = useBearStore((state) => state.bears)
// Bad - rerenders on any state change
const state = useBearStore()
// Bad in v5 - new object every render triggers infinite loop!
// const { bears, fish } = useBearStore((s) => ({ bears: s.bears, fish: s.fish }))
// Good - multiple values with useShallow
const { bears, fish } = useBearStore(
useShallow((state) => ({ bears: state.bears, fish: state.fish }))
)
// Array destructuring with useShallow
const [bearsVal, fishVal] = useBearStore(
useShallow((state) => [state.bears, state.fish])
)
If you need createWithEqualityFn, import it from 'zustand/traditional' (requires use-sync-external-store as a peer dependency in v5).
Access Outside Components
const state = useBearStore.getState()
useBearStore.setState({ bears: 5 })
const unsub = useBearStore.subscribe((state) => console.log(state))
unsub()
Vanilla Store (No React)
import { createStore } from 'zustand/vanilla'
const store = createStore<BearState>()((set) => ({
bears: 0,
increase: (by) => set((state) => ({ bears: state.bears + by })),
}))
store.getState().bears
store.setState({ bears: 10 })
Additional Documentation
- Middleware: See references/middleware.md for
persist,devtools,immer,subscribeWithSelector, and SSR hydration - Patterns: See references/patterns.md for slices, Vitest reset, transient updates, and React 19 Context DI
- TypeScript: See references/typescript.md for curried
create<T>()(...),StateCreator,ExtractState, andzustand/traditional
Key Patterns
| Pattern | When to Use |
|---|---|
| Single selector | One primitive/function slice needed |
useShallow (zustand/react/shallow) |
Selecting multiple fields as object or tuple |
getState() / setState() |
Outside React or inside non-hook event handlers |
subscribe() |
External systems, transient refs |
createStore (zustand/vanilla) |
Framework-agnostic or React Context DI stores |
Gates (persist and devtools)
Before merging code that uses these middlewares (see references/middleware.md for setup):
persist— Pass when persisted keys are explicit (partializeor a reviewed full-state snapshot) and the JSON written to storage cannot include auth tokens, API keys, or other secrets.devtoolsin shipped bundles — Pass when DevTools runs only in development (enabled: import.meta.env.DEVor env gate), or you leave a one-line note in the PR explaining why it stays enabled in production.
Установить zustand-state в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл zustand-state?
Zustand v5 state management for React and vanilla TypeScript. Use when creating stores with curried create<T>()(...), preventing infinite selector re-renders with useShallow, persisting state with partialize, configuring devtools/immer, or injecting stores via React Context.
Как установить скилл zustand-state?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл zustand-state запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic