state-management-expert

Implements React state management patterns using Zustand, Redux Toolkit, TanStack Query, and Context API.

3|Updated Jan 15, 2026
One-click install
npx skills add https://github.com/trudyan141/my-antigravity-agents-kit --skill state-management-expert-trudyan141
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: state-management-expert
Source: https://github.com/trudyan141/my-antigravity-agents-kit/tree/main/templates/.agent/skills/state-management-expert
Command: npx skills add https://github.com/trudyan141/my-antigravity-agents-kit --skill state-management-expert-trudyan141

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Choosing and implementing the right React state management approach is confusing, and wrong choices lead to prop drilling, unnecessary re-renders, and duplicated server state. ## Core Features & Use Cases - Decision Tree Guidance: Routes state types (server, global UI, form, URL, local) to the appropriate library such as TanStack Query, Zustand, or React Hook Form. - Ready-to-Use Patterns: Provides TypeScript implementations for Zustand stores with persist/devtools middleware, Redux Toolkit slices, TanStack Query hooks with cache invalidation, and typed Context providers. - Code Review Checklist: Flags anti-patterns like storing server data in Redux, missing selectors, and duplicate state. - Use Case: When building a React app that fetches API data and shares user session state globally, use this Skill to set up TanStack Query for server data and a persisted Zustand store for the session. ## Quick Start Ask the AI to set up state management for your React app, for example: create a Zustand store for user authentication and TanStack Query hooks for fetching posts.

Frequently Asked Questions about state-management-expert

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I choose between Zustand and Redux Toolkit for React state?

Zustand is recommended for most apps due to its minimal boilerplate and built-in middleware like persist and devtools. Redux Toolkit suits larger teams needing strict conventions, slice-based reducers, and the Redux DevTools ecosystem.

Should I store API data in Redux or Zustand?

No, server state should use TanStack Query or SWR instead of Redux or Zustand. These libraries handle caching, stale time, background refetching, and cache invalidation automatically, which global stores do not.

How do I persist Zustand state to localStorage?

Wrap your Zustand store creator with the persist middleware from zustand/middleware and provide a storage name. The store state then automatically syncs to localStorage and rehydrates on page load.

Does TanStack Query support optimistic updates for mutations?

Yes, TanStack Query supports optimistic updates through the onMutate callback where you update the cache before the request completes. On success, use queryClient.invalidateQueries to refetch fresh server data.

Why does my React Context cause unnecessary re-renders?

Context re-renders all consumers whenever any value in the provider changes. Fix this by memoizing the context value with useMemo, splitting large contexts into smaller ones, or switching to Zustand selectors.

When should I use useState instead of a global state library?

Use useState or useReducer for local component state that is not shared beyond one or two levels. Global state libraries add unnecessary complexity for local concerns and should be reserved for truly shared state.