State management is an AI agent skill from the GitHub repository rnavarych/alpha-engineer. State management expertise including local vs global state decisions, Redux Toolkit, Zustand, Jotai, MobX, Context API patterns, server state (React Query, SWR) vs client state, optimistic updates, and state machines with XState.
Claude Code: save it as .claude/skills/state-management/SKILL.md
Cursor: save it as .cursor/rules/state-management.md
Codex: save it as .agents/skills/state-management/SKILL.md
ChatGPT, Gemini and other assistants: paste it into custom or project instructions
Skill file
State Management
When to use
Deciding where state lives — local, global, server cache, URL, or form
Setting up Zustand, Jotai, or Redux Toolkit stores
Replacing axios+useState patterns with TanStack Query
Implementing optimistic updates for mutations
Building complex UI flows with XState state machines
Migrating from Redux to Zustand, or Context to a proper store
Diagnosing unnecessary re-renders from over-broad state subscriptions
Core principles
Server state belongs in TanStack Query or SWR — never duplicate API data in a client store
URL is state too — pagination, filters, search: use nuqs or router search params
Keep it local as long as possible — global state is a last resort, not a default
Selectors prevent re-renders — subscribe to slices, not the whole store
XState for impossible states — if "loading" and "error" can't coexist, the machine enforces it
Reference Files
references/react-state-primitives.md — state category decision table, useState/useReducer patterns, useContext (when/when not), useSyncExternalStore, React 19 use(), stale closure prevention
references/server-state-tanstack-query.md — TanStack Query v5 queries, optimistic mutations with onMutate/onError/onSettled, infinite queries, prefetch on hover, SWR alternative
references/global-state-zustand-jotai-redux.md — Zustand with immer/persist/devtools middleware, granular selectors, Jotai atom composition, RTK createSlice/createEntityAdapter, URL state with nuqs, React Hook Form + Zod, XState machines, Preact signals, anti-patterns
Use this skill with your AI agent:Open on Skill Issue to copy, download, or add to your library.
Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.