Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
existential-birds avatar

Zustand State

  • 232 installs
  • 74 repo stars
  • Updated July 21, 2026
  • existential-birds/beagle

Design Zustand stores with slices, selectors, middleware, and persistence patterns that avoid unnecessary re-renders in React and React Native apps.

About

Frontend build skill for Zustand: helps model global and feature stores, memoized selectors, devtools middleware, and persist rehydration so React web and native clients stay predictable without Redux boilerplate.

  • Store slice design
  • Selector optimization
  • Middleware patterns
  • Persist hydration
  • React Native parity

Zustand State by the numbers

  • 232 all-time installs (skills.sh)
  • Ranked #818 of 2,245 Frontend Development skills by installs in the Skillselion catalog
  • Data as of Jul 28, 2026 (Skillselion catalog sync)
npx skills add https://github.com/existential-birds/beagle --skill zustand-state

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs232
repo stars74
Last updatedJuly 21, 2026
Repositoryexistential-birds/beagle

What it does

Design Zustand stores with slices, selectors, middleware, and persistence patterns that avoid unnecessary re-renders in React and React Native apps.

Files

SKILL.mdMarkdownGitHub ↗

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

// 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 }, true)

Selectors & Performance

// Good - subscribes only to bears
const bears = useBearStore((state) => state.bears)

// Bad - rerenders on any change
const state = useBearStore()

// Multiple values with useShallow (prevents rerenders with shallow comparison)
import { useShallow } from 'zustand/react/shallow'

const { bears, fish } = useBearStore(
  useShallow((state) => ({ bears: state.bears, fish: state.fish }))
)

// Array destructuring also works
const [bears, fish] = useBearStore(
  useShallow((state) => [state.bears, state.fish])
)

Access Outside Components

// Get current state (non-reactive)
const state = useBearStore.getState()

// Update state
useBearStore.setState({ bears: 5 })

// Subscribe to changes
const unsub = useBearStore.subscribe((state) => console.log(state))
unsub() // unsubscribe

Vanilla Store (No React)

import { createStore } from 'zustand/vanilla'

const store = createStore((set) => ({
  bears: 0,
  increase: (by) => set((state) => ({ bears: state.bears + by })),
}))

store.getState().bears
store.setState({ bears: 10 })
store.subscribe((state) => console.log(state))

Additional Documentation

  • Middleware: See references/middleware.md for persist, devtools, immer
  • Patterns: See references/patterns.md for slices, testing, best practices
  • TypeScript: See references/typescript.md for advanced typing patterns

Key Patterns

PatternWhen to Use
Single selectorOne piece of state needed
useShallowMultiple values, avoid rerenders
getState()Outside React, event handlers
subscribe()External systems, logging
Vanilla storeNon-React environments

Gates (persist and devtools)

Before merging code that uses these middlewares (see references/middleware.md for setup):

1. `persist`Pass when persisted keys are explicit (partialize or a reviewed full-state snapshot) and the JSON written to storage cannot include auth tokens, API keys, or other secrets. 2. `devtools` in shipped bundlesPass when DevTools runs only in development (env gate), or you leave a one-line note in the PR explaining why it stays enabled in production.

Related skills

Frontend Developmentfrontendintegrations

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.