react-state-management

Implements React state management patterns using Redux Toolkit, Zustand, Jotai, and React Query.

1|Updated Aug 4, 2026
One-click install
npx skills add https://github.com/Hamzaoui-Louai/LEAN-gym-dashboard-frontend --skill react-state-management-hamzaoui-louai
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: react-state-management
Source: https://github.com/Hamzaoui-Louai/LEAN-gym-dashboard-frontend/tree/main/.opencode/skills/react-state-management
Command: npx skills add https://github.com/Hamzaoui-Louai/LEAN-gym-dashboard-frontend --skill react-state-management-hamzaoui-louai

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Choosing and implementing the right state management approach in React is confusing, with overlapping options for local, global, server, URL, and form state. This Skill provides concrete patterns and selection criteria so you can set up stores, server-state caching, and optimistic updates correctly the first time. ## Core Features & Use Cases - Library Selection Guidance: Decision criteria for choosing between Redux Toolkit, Zustand, Jotai, and React Query based on app size and state type. - Ready-to-Use Patterns: TypeScript implementations of typed Redux slices with async thunks, Zustand slice composition with selective subscriptions, Jotai atoms with derived and async state, and React Query hooks with optimistic updates. - Migration Support: Step-by-step guidance for migrating legacy Redux boilerplate to modern Redux Toolkit with createSlice and Immer. - Use Case: When building a dashboard that mixes UI state (sidebar toggles, modals) with server data (user lists, stats), use this Skill to combine Zustand for client state and React Query for server state with proper cache invalidation. ## Quick Start Ask the AI to set up a Zustand store with TypeScript for user authentication state, or to refactor an existing Redux slice to Redux Toolkit.

Frequently Asked Questions about react-state-management

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

FAQPage Schema
How do I choose between Redux Toolkit, Zustand, and Jotai?

Choose based on app size and state complexity: Zustand or Jotai for small apps with simple state, Redux Toolkit for large apps with complex state, and Jotai when you need atomic granular updates. For heavy server interaction, pair React Query with a light client state library.

How do I implement optimistic updates with React Query?

Use the onMutate callback to cancel outgoing queries, snapshot the previous data with getQueryData, and set the new value with setQueryData. On error, roll back using the snapshot, and on settle, invalidate the query key to refetch fresh data.

Should I use React Query or Redux for server state?

Use React Query for server state since it handles caching, refetching, and staleness automatically. Reserve Redux Toolkit or Zustand for client-only state like UI toggles and modals, and avoid duplicating server data in global stores.

How do I prevent unnecessary re-renders with Zustand?

Use selective subscriptions by passing a selector function to the store hook, such as useStore((state) => state.user). Components then only re-render when their selected slice changes, not when unrelated store fields update.

How do I migrate legacy Redux to Redux Toolkit?

Replace action type constants and switch-based reducers with createSlice, which generates actions automatically and allows mutable-style updates via Immer. Use createAsyncThunk for async logic instead of handwritten thunk action creators.

When should state not be put in a global store?

Avoid globalizing component-specific UI state, derived data that can be computed, and server data that React Query already manages. Colocate state as close to where it is used as possible to reduce coupling and re-render scope.