react-use-state

Guides correct usage of the React useState hook for component state management.

Updated Apr 29, 2026
One-click install
npx skills add https://github.com/dev-khoi/AURA-conHack-2026 --skill react-use-state-dev-khoi
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: react-use-state
Source: https://github.com/dev-khoi/AURA-conHack-2026/tree/main/.opencode/skills/react-use-state
Command: npx skills add https://github.com/dev-khoi/AURA-conHack-2026 --skill react-use-state-dev-khoi

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Developers often misuse React's useState hook by mutating state directly, storing redundant derived values, or choosing the wrong hook for the job, leading to stale UI, missed re-renders, and hard-to-debug components. ## Core Features & Use Cases - Hook Selection Guidance: Clear decision rules for when to use useState versus useRef, useReducer, useMemo, or Context. - Critical Rules Reference: Covers immutability, asynchronous state updates, updater functions, lazy initializers, and top-level hook calls. - Common Patterns Library: Ready-to-apply patterns for resetting state with keys, storing functions in state, and updating nested objects and arrays. - Use Case: When a developer's counter only increments once despite three setCount calls, this Skill explains the stale-closure issue and provides the updater-function fix. ## Quick Start Ask the AI to review your React component's useState usage and explain why a state update is not triggering a re-render.

Frequently Asked Questions about react-use-state

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

FAQPage Schema
How do I update state based on the previous state in React?▼

Pass an updater function to the setter, such as setCount(c => c + 1), instead of referencing the state variable directly. This guarantees each update receives the latest queued value, which matters when multiple updates run in the same event handler.

When should I use useReducer instead of useState?▼

Use useReducer when state has multiple related sub-values, when the next state depends on the previous one in complex ways, or when you want to centralize transition logic in a reducer function. useState fits simple, independent values.

Why does my state not update immediately after calling setState?▼

State updates are asynchronous and batched by React, so reading the variable right after calling the setter returns the old snapshot. Compute the next value into a local variable if you need it immediately, or use useEffect to react to changes.

Should I store derived values in useState?▼

No. Values computable from props or other state should be calculated during render, or wrapped in useMemo if the computation is expensive. Storing derived values creates redundant state that can drift out of sync.

Why is mutating state directly not working in React?▼

React detects changes by comparing object references, so mutating an existing object or array and passing it back to the setter is ignored. Always create a new object or array using spread syntax, map, or filter when updating state.