react-state-context-reducer

Implements React Context with useReducer for multi-field client state management.

Updated Jul 27, 2026
One-click install
npx skills add https://github.com/arayaroma/ether --skill react-state-context-reducer-arayaroma
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: react-state-context-reducer
Source: https://github.com/arayaroma/ether/tree/main/skills/react-state-context-reducer
Command: npx skills add https://github.com/arayaroma/ether --skill react-state-context-reducer-arayaroma

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? When a slice of React state has several related fields (loading, error, data) and multiple distinct ways to change it, scattered useState calls drift out of sync and become hard to maintain. This Skill provides the Context + useReducer pattern to centralize that state with a typed action union. ## Core Features & Use Cases - Typed Reducer Pattern: Defines a State interface and a discriminated Action union so every state transition is explicit and type-checked. - Context Provider with Custom Hook: Wraps useReducer in a Provider component and exposes a typed hook (e.g. useMarkets) that throws when used outside the provider. - Guidance on Boundaries: Explains when plain useState, Zustand/Redux, or SWR/React Query are better fits, and how provider placement affects re-renders. - Use Case: A markets feature needs markets list, selected market, and loading flag updated through several actions; this Skill scaffolds a MarketProvider and useMarkets hook instead of three independent useState calls. ## Quick Start Refactor my component's related useState calls into a Context plus useReducer pattern with a typed action union and a custom hook.

Frequently Asked Questions about react-state-context-reducer

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

FAQPage Schema
How do I use Context with useReducer in React?▼

Define a State interface and a typed Action union, write a reducer handling each action type, then create a Context holding state and dispatch. Wrap children in a Provider that calls useReducer, and expose a custom hook that reads the context and throws if undefined.

When should I use useReducer instead of useState?▼

Use useReducer when a state slice has several fields that change together and multiple distinct actions mutate it, such as loading, error, and data. For one or two independent booleans or strings, plain useState is simpler and sufficient.

Context useReducer vs Zustand or Redux for state management?▼

Context plus useReducer suits client-owned UI state local to a feature. Choose Zustand or Redux when state is genuinely global across routes and needs persistence, devtools, or cross-tab sync, which hand-rolled Context does not provide.

Can I use Context and useReducer for server data fetching?▼

No, this pattern is for client-owned UI state, not server-derived data. For data with caching and revalidation needs, use SWR or React Query instead of storing fetched data in a reducer.

Why does my Context provider cause unnecessary re-renders?▼

Context consumers re-render on any value change, not just the field they read. Mount the provider as close as possible to the components that need it rather than at the app root to limit the re-render scope.