# Zustand Stores

> Zustand state management patterns - auth store with SSR-safe initialization and store best practices Use when this capability is needed.

- Skill: `tomevault-io/zustand-stores` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add tomevault-io/zustand-stores`
- Raw SKILL.md: https://api.skillmd.com/api/skills/tomevault-io/zustand-stores/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: tomevault-io (https://skillmd.com/u/tomevault-io)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/tomevault-io/zustand-stores

---


## When to Use Zustand

Zustand is for **shared client state** — UI preferences, sidebar collapsed, feature toggles, etc.

Auth state is managed by React Query (`queryKeys.me` cache + `useAuth()` hook) — not Zustand.

## Store Pattern

```typescript
import { create } from 'zustand';

interface UIState {
  sidebarOpen: boolean;
  toggleSidebar: () => void;
}

export const useUIStore = create<UIState>()((set) => ({
  sidebarOpen: true,
  toggleSidebar: () => set((s) => ({ sidebarOpen: !s.sidebarOpen })),
}));
```

## Rules

- Check `typeof window !== 'undefined'` before accessing browser globals
- Use selectors: `useUIStore((s) => s.sidebarOpen)`, never destructure the whole store
- Access outside React: `useUIStore.getState()`

---
> Converted and distributed by [TomeVault](https://tomevault.io/claim/aexol-studio) — claim your Tome and manage your conversions.
<!-- tomevault:4.0:skill_md:2026-04-11 -->

