using-reducers

Manage complex React 19 state with useReducer and dispatched actions.

Updated Nov 21, 2025
One-click install
npx skills add https://github.com/djankies/claude-configs --skill using-reducers
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: using-reducers
Source: https://github.com/djankies/claude-configs/tree/main/react-19/skills/using-reducers
Command: npx skills add https://github.com/djankies/claude-configs --skill using-reducers

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Teaches useReducer for complex state logic in React 19. Use when state updates depend on previous state, multiple related state values, or complex update logic.

Core Features & Use Cases

  • Structured state management: central reducer to orchestrate state transitions.
  • Predictable updates: rely on dispatched actions rather than scattered setState calls.
  • Use case: manage a multi-field form with dependent fields and a reset action.

Quick Start

Run sample counter with a reducer to handle increment, decrement, and reset. Refer to the code snippet in the Skill body for a complete example.

Frequently Asked Questions about using-reducers

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

FAQPage Schema
When should I use useReducer instead of useState for state management in React?

useReducer is best for complex state logic where updates depend on previous state, multiple related state values, or intricate update patterns. Use it for multi-field forms, todo lists, or counters with dynamic behavior where useState would lead to scattered setState calls.

How do I manage state with multiple related values in React components?

useReducer centralizes state transitions through a reducer function that handles all state shape updates in one place. Dispatch actions to trigger predictable state changes, keeping related values synchronized and update logic organized.

How does a reducer function work with useReducer in React 19?

A reducer receives current state and an action object, then returns the new state. It enables deterministic state transitions where each action maps to a specific state change, allowing you to reset, increment, decrement, or handle complex logic based on action type.

Can I use useReducer for form state with dependent fields and reset functionality?

Yes, useReducer handles multi-field forms where fields depend on each other. Define actions for field updates and a reset action that returns initialState, centralizing form logic and making dependent updates predictable and maintainable.

What happens if I dispatch an unknown action to my reducer?

The reducer should throw an error for unknown actions, catching logic mistakes early. This enforces strict action contracts and prevents silent failures, ensuring only defined state transitions occur.

How do I initialize state when using useReducer?

Pass an initialState object and optional init function to useReducer. The init function runs once on mount to compute derived initial state, then the reducer function handles all subsequent state updates via dispatch.