state-management

Implement React Query and Zustand patterns for server and client state.

Updated May 17, 2026
One-click install
npx skills add https://github.com/cenjie/skills --skill state-management-cenjie
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: state-management
Source: https://github.com/cenjie/skills/tree/main/skills/state-management
Command: npx skills add https://github.com/cenjie/skills --skill state-management-cenjie

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Provides clear, production-oriented patterns to implement, maintain, and refactor server and client state in React applications so teams avoid cache collisions, inconsistent local state, and fragile mutation logic.

Core Features & Use Cases

  • Server state patterns: Query key factories, query function best practices, staleTime/gcTime strategies, refetch and retry configuration.
  • Mutation and update workflows: Proper useMutation setup, optimistic updates with rollback, onMutate/onError/onSettled callbacks, and targeted invalidation.
  • Client state with Zustand: Typed store creation, selectors for render performance, persist middleware, devtools integration, and combining Zustand with React Query for hybrid state.
  • Advanced scenarios: Infinite and paginated queries, dependent and parallel queries, cancellation, prefetching strategies, and Suspense/ErrorBoundary integration.

Quick Start

Apply the state-management patterns to audit and improve data fetching, caching, mutation handling, and Zustand stores in your React project.

Frequently Asked Questions about state-management

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

FAQPage Schema
How do I structure React Query keys to avoid cache collisions?

React Query cache collisions are avoided by using query key factories—structured functions that generate hierarchical keys for each query. This pattern ensures targeted invalidation and consistent caching across server state in React applications.

What's the best way to implement optimistic updates with React Query mutations?

Optimistic updates with React Query use onMutate to cache pre-mutation data, onError to rollback on failure, and onSettled for invalidation. This workflow provides immediate UI feedback while maintaining data consistency.

When should I use Zustand instead of React Query for state management?

Zustand manages local UI state while React Query handles server state like fetched and cached data. Use Zustand for client-side interactions, persist middleware, and devtools, combining both for hybrid state architectures.

How do I set up infinite and paginated queries with React Query in TypeScript?

Infinite and paginated queries in React Query require TypeScript typing, proper query function structure, and configured staleTime and gcTime strategies. These patterns support dependent and parallel queries alongside prefetching.

Does React Query work with Suspense and ErrorBoundary for data fetching?

React Query integrates with Suspense and ErrorBoundary for declarative data fetching. This approach handles loading and error states at the component tree level, streamlining async UI rendering in React applications.