PluginBench
Skill
Pass
Audit score 90

react-state-management

wshobson/agents

Master Redux Toolkit, Zustand, Jotai, and React Query for modern state management.

What is react-state-management?

Comprehensive guide to React state management covering local, global, server, URL, and form state. Use this skill when setting up global state management, choosing between solutions, managing server state, or migrating from legacy patterns.

  • Compare and select between Redux Toolkit, Zustand, Jotai, and React Query based on app complexity
  • Set up global state stores with TypeScript and middleware support
  • Manage server state and caching with React Query or RTK Query
  • Implement optimistic updates and normalized data structures
  • Debug state-related issues using devtools and selectors
  • Migrate from legacy Redux to modern Redux Toolkit patterns

How to install react-state-management

npx skills add https://github.com/wshobson/agents --skill react-state-management
Claude Code
Cursor
Windsurf
Cline

How to use react-state-management

  1. 1.Identify your state category (local, global, server, URL, or form)
  2. 2.Select the appropriate solution using the selection criteria table
  3. 3.Follow the Quick Start example for your chosen library (Zustand shown)
  4. 4.Implement selectors to prevent unnecessary re-renders
  5. 5.Separate server state management from client state management
  6. 6.Refer to references/details.md for advanced patterns and worked examples

Use cases

Good for
  • Setting up global state in a new React application
  • Choosing the right state management solution for project requirements
  • Managing remote data and caching with React Query
  • Implementing theme switching or user authentication state
  • Normalizing and updating complex nested data structures
Who it's for
  • React developers building medium to large applications
  • Teams migrating from legacy Redux patterns
  • Developers choosing between multiple state management libraries
  • Full-stack engineers managing both client and server state
  • TypeScript-first development teams

react-state-management FAQ

When should I use Zustand vs Redux Toolkit?

Use Zustand for small to medium apps with simple state. Use Redux Toolkit for large apps with complex state, middleware needs, or team familiarity with Redux patterns.

Should I store server data in global state?

No. Use React Query or RTK Query to manage server state separately. Keep global state for client-only data like theme or UI preferences.

How do I prevent unnecessary re-renders?

Use selectors to subscribe to only the state slices you need. Both Zustand and Redux Toolkit support selective subscriptions.

Can I use multiple state management solutions together?

Yes. Separate concerns: use React Query for server state, Zustand/Redux for client state, React Router for URL state, and React Hook Form for form state.

How do I migrate from legacy Redux?

Use Redux Toolkit's createSlice to replace action creators and reducers. It uses Immer internally for immutable updates and reduces boilerplate significantly.

Full instructions (SKILL.md)

Source of truth, from wshobson/agents.


name: react-state-management description: Master modern React state management with Redux Toolkit, Zustand, Jotai, and React Query. Use when setting up global state, managing server state, or choosing between state management solutions.

React State Management

Comprehensive guide to modern React state management patterns, from local component state to global stores and server state synchronization.

When to Use This Skill

  • Setting up global state management in a React app
  • Choosing between Redux Toolkit, Zustand, or Jotai
  • Managing server state with React Query or SWR
  • Implementing optimistic updates
  • Debugging state-related issues
  • Migrating from legacy Redux to modern patterns

Core Concepts

1. State Categories

TypeDescriptionSolutions
Local StateComponent-specific, UI stateuseState, useReducer
Global StateShared across componentsRedux Toolkit, Zustand, Jotai
Server StateRemote data, cachingReact Query, SWR, RTK Query
URL StateRoute parameters, searchReact Router, nuqs
Form StateInput values, validationReact Hook Form, Formik

2. Selection Criteria

Small app, simple state → Zustand or Jotai
Large app, complex state → Redux Toolkit
Heavy server interaction → React Query + light client state
Atomic/granular updates → Jotai

Quick Start

Zustand (Simplest)

// store/useStore.ts
import { create } from 'zustand'
import { devtools, persist } from 'zustand/middleware'

interface AppState {
  user: User | null
  theme: 'light' | 'dark'
  setUser: (user: User | null) => void
  toggleTheme: () => void
}

export const useStore = create<AppState>()(
  devtools(
    persist(
      (set) => ({
        user: null,
        theme: 'light',
        setUser: (user) => set({ user }),
        toggleTheme: () => set((state) => ({
          theme: state.theme === 'light' ? 'dark' : 'light'
        })),
      }),
      { name: 'app-storage' }
    )
  )
)

// Usage in component
function Header() {
  const { user, theme, toggleTheme } = useStore()
  return (
    <header className={theme}>
      {user?.name}
      <button onClick={toggleTheme}>Toggle Theme</button>
    </header>
  )
}

Detailed patterns and worked examples

Detailed pattern documentation lives in references/details.md. Read that file when the navigation tier above is insufficient.

Best Practices

Do's

  • Colocate state - Keep state as close to where it's used as possible
  • Use selectors - Prevent unnecessary re-renders with selective subscriptions
  • Normalize data - Flatten nested structures for easier updates
  • Type everything - Full TypeScript coverage prevents runtime errors
  • Separate concerns - Server state (React Query) vs client state (Zustand)

Don'ts

  • Don't over-globalize - Not everything needs to be in global state
  • Don't duplicate server state - Let React Query manage it
  • Don't mutate directly - Always use immutable updates
  • Don't store derived data - Compute it instead
  • Don't mix paradigms - Pick one primary solution per category

Migration Guides

From Legacy Redux to RTK

// Before (legacy Redux)
const ADD_TODO = "ADD_TODO";
const addTodo = (text) => ({ type: ADD_TODO, payload: text });
function todosReducer(state = [], action) {
  switch (action.type) {
    case ADD_TODO:
      return [...state, { text: action.payload, completed: false }];
    default:
      return state;
  }
}

// After (Redux Toolkit)
const todosSlice = createSlice({
  name: "todos",
  initialState: [],
  reducers: {
    addTodo: (state, action: PayloadAction<string>) => {
      // Immer allows "mutations"
      state.push({ text: action.payload, completed: false });
    },
  },
});