react-hooks-effects

Defines principles for using React hooks and effects correctly in SPA applications.

1|Updated Apr 15, 2026
One-click install
npx skills add https://github.com/pnewsam/skills --skill react-hooks-effects-pnewsam
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: react-hooks-effects
Source: https://github.com/pnewsam/skills/tree/main/archive/react-pilot/react-hooks-effects
Command: npx skills add https://github.com/pnewsam/skills --skill react-hooks-effects-pnewsam

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? React developers frequently misuse useEffect for derived state, event logic, and data fetching, leading to stale closures, memory leaks, race conditions, and Strict Mode failures. This Skill provides clear principles for when and how to use hooks correctly. ## Core Features & Use Cases - Effect Discipline: Distinguishes effects that synchronize with external systems (browser APIs, subscriptions, timers) from logic that belongs in event handlers or render. - Dependency and Cleanup Rules: Explains dependency arrays as declarations of reactive values, mandates cleanup for subscriptions, and covers AbortController-based fetch cancellation. - Modern React Patterns: Covers useRef vs useState, custom hook extraction, useEffectEvent and use() on React 19+, and Strict Mode idempotency. - Use Case: When reviewing a component that fetches invoice data in a useEffect, apply this Skill to add cancellation, fix the dependency array, and recommend TanStack Query for server state. ## Quick Start Review this React component's hooks and effects and fix any stale closures, missing cleanup, or unnecessary derived state.

Frequently Asked Questions about react-hooks-effects

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

FAQPage Schema
When should I use useEffect in React?▼

Use useEffect only to synchronize with systems outside React, such as browser APIs, WebSocket subscriptions, timers, or third-party widgets. Do not use it for values calculable during render or logic triggered by user actions, which belong in event handlers.

How do I avoid stale closures in React hooks?▼

Avoid stale closures by using functional state updates, including all changing values in dependency arrays, and keeping async work cancellable. On React 19.2+, useEffectEvent reads the latest props and state inside an effect without re-triggering it.

Should I fetch data with useEffect or TanStack Query?▼

Prefer a server-state library like TanStack Query or SWR for API data in production apps. Manual effect fetching is acceptable for one-off integrations but must handle cancellation with AbortController and race conditions.

Why does my effect run twice in React Strict Mode?▼

Strict Mode intentionally mounts, unmounts, and remounts components in development to expose unsafe effects. Fix this by making effects idempotent with full cleanup, not by disabling Strict Mode or adding flags that hide missing cleanup.

When should I use useRef instead of useState?▼

Use useRef for mutable values that survive renders without triggering UI updates, such as DOM nodes, timeout IDs, or previous values for comparison. Use useState when the interface should re-render in response to the value changing.