skillfed

zustand-state

Zustand State is a minimal state management solution designed for React and vanilla JavaScript applications. It eliminates boilerplate by removing the need for providers and offers fine-grained control through selectors to optimize component rerenders. The skill covers store creation, state updates, performance patterns, and integration with middleware like persistence and devtools.

Zustand State provides lightweight global state management for React with minimal boilerplate and no provider setup required.

AI-generated summary based on this skill's SKILL.md

74 10 Apache-2.0 updated by existential-birds

Install

existential-birds/beagle/zustand-state · repository language: TypeScript

git clone https://github.com/existential-birds/beagle
cp -r beagle/plugins/beagle-react/skills/zustand-state ~/.claude/skills/zustand-state
npx skillfed install existential-birds/beagle/zustand-state

Frequently asked questions

AI-generated answers based on this skill's SKILL.md and metadata

How do I create a zustand store?

Zustand State lets you create a store by calling `create()` with a function that receives `set` and `get`. Define your state and actions directly: `const useStore = create((set) => ({ count: 0, increment: () => set(state => ({ count: state.count + 1 })) }))`. No providers needed—import and use the hook anywhere in your React app. Zustand State handles subscriptions automatically.

What is zustand selector performance and how does useShallow help?

Zustand State selectors let you pick specific state slices to prevent unnecessary rerenders. Use `useStore((state) => state.count)` to subscribe only to `count` changes. The `useShallow` hook compares shallow equality on objects or arrays, reducing rerenders when nested state changes but the shallow structure stays the same. This optimization keeps your components efficient.

How can I persist zustand state to localStorage?

Zustand State includes a persist middleware that automatically syncs state to localStorage. Wrap your store with `persist()`: `create(persist((set) => ({ ... }), { name: 'my-store' }))`. On app load, the stored state hydrates automatically. You can customize storage, merge strategies, and which fields persist.

Can I access and update zustand state outside React components?

Yes. Zustand State stores expose `getState()` and `setState()` methods. Call `useStore.getState()` to read state or `useStore.setState({ count: 5 })` to update it from anywhere—event handlers, API calls, or vanilla JavaScript. You can also subscribe to changes with `useStore.subscribe()` without React hooks.

How do I integrate zustand devtools for debugging?

Zustand State works with Redux DevTools via the devtools middleware. Wrap your store: `create(devtools((set) => ({ ... }), { name: 'MyStore' }))`. You'll see all state changes, time-travel debugging, and action history in the Redux DevTools browser extension. Combine it with persist for full state management visibility.

Is zustand state management suitable for vanilla JavaScript without React?

Yes. Zustand State works in vanilla JavaScript by creating stores without React hooks. Use `create()` to define state and actions, then call `getState()`, `setState()`, and `subscribe()` directly. No React dependency required—ideal for vanilla apps, Node.js scripts, or non-React frameworks needing lightweight global state.

SKILL.md

rendered from the published skill — quoted content, verbatim

Zustand State Management

Minimal state management - no providers, minimal boilerplate.

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

```typescript // Flat updates (auto-merged at one level) set({ bears: 5 }) set((state) => ({ bears: state.bears + 1 }))

// Nested objects (manual spread required) set((state) => ({ nested: { ...state.nested, count: state.nested.count + 1 } }))

// Replace entire state (no merge) set({ bears: 0 },

(truncated - see the full file via the links below)

Read as markdown · JSON record · Browse the source repository

File tree — 7 files
plugins/beagle-react/skills/zustand-state/MIDDLEWARE.md
plugins/beagle-react/skills/zustand-state/PATTERNS.md
plugins/beagle-react/skills/zustand-state/SKILL.md
plugins/beagle-react/skills/zustand-state/TYPESCRIPT.md
plugins/beagle-react/skills/zustand-state/references/middleware.md
plugins/beagle-react/skills/zustand-state/references/patterns.md
plugins/beagle-react/skills/zustand-state/references/typescript.md

Related skills

Tags

state-container hook-based-api provider-less selector-optimization middleware-extensible vanilla-js-support dev-tooling persistence-layer