react-use-state

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

Updated Aug 16, 2026
One-click install
npx skills add https://github.com/Aveer/skills --skill react-use-state-aveer
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: react-use-state
Source: https://github.com/Aveer/skills/tree/main/skills/react-use-state
Command: npx skills add https://github.com/Aveer/skills --skill react-use-state-aveer

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Developers frequently misuse React's useState hook by mutating state directly, reading stale values after updates, storing redundant derived data, or choosing the wrong hook for the job, leading to subtle bugs and unnecessary re-renders. ## Core Features & Use Cases - Hook Selection Guidance: Clarifies when to use useState versus useRef, useReducer, useMemo, useContext, or external stores like Zustand and TanStack Query. - Critical Rules Reference: Covers immutability, asynchronous updates, updater functions, lazy initializers, and top-level hook calls with correct and incorrect code examples. - Use Case: When a counter only increments once despite calling setCount three times, consult this Skill to learn that updater functions like setCount(c => c + 1) are required for sequential updates. ## 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 queues updates against the latest value, so multiple sequential calls accumulate correctly rather than reusing a stale snapshot.

When should I use useState vs useReducer in React?▼

Use useState for simple, local state with direct value replacement. Switch to useReducer when state has multiple related sub-values, next state depends on previous state in complex ways, or you want to centralize transition logic in a reducer function.

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

State updates are asynchronous and batched, so the state variable keeps its old value within the same render. Compute the next value into a local variable if you need it immediately, or use an updater function for subsequent updates.

Why is mutating state directly not working in React?▼

React relies on reference comparison to detect changes, so mutating an object or array in place and passing the same reference to the setter is ignored. Always create a new object or array using spread syntax, map, or filter.

Should I store derived values in useState?▼

No, values computable from props or other state should be calculated during render instead of stored. For expensive computations, wrap the calculation in useMemo to avoid redundant work on every render.