react-useeffect

Guides correct useEffect usage in React with anti-patterns and alternatives.

3|Updated Apr 20, 2026
One-click install
npx skills add https://github.com/langgenius/due-date-hq-jwl --skill react-useeffect-langgenius
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: react-useeffect
Source: https://github.com/langgenius/due-date-hq-jwl/tree/main/.agents/skills/react-useeffect
Command: npx skills add https://github.com/langgenius/due-date-hq-jwl --skill react-useeffect-langgenius

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? React developers frequently overuse useEffect for tasks like deriving state, handling user events, and resetting state, which causes extra re-renders, stale data, race conditions, and hard-to-debug Effect chains. ## Core Features & Use Cases - Quick Reference and Decision Tree: A DO/DON'T table and flowchart that map common scenarios (derived state, prop changes, user events, data fetching) to the right React pattern. - Nine Anti-Patterns with Fixes: Detailed bad/good code examples covering redundant derived state, Effect chains, parent notification via Effect, fetching without cleanup, and app initialization pitfalls. - Eight Better Alternatives: Patterns including calculating during render, useMemo, the key prop, useSyncExternalStore, lifting state up, and custom data-fetching hooks with cleanup. - Use Case: When a search component shows stale results because fast typing triggers out-of-order fetch responses, apply the cleanup-flag pattern to ignore stale responses and eliminate the race condition. ## Quick Start Ask the assistant to review your React component's useEffect code and recommend whether an Effect is needed or a better alternative applies.

Frequently Asked Questions about react-useeffect

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 external systems such as browser APIs, third-party widgets, subscriptions, or analytics that run because a component displayed. If no external system is involved, prefer event handlers, render-time calculation, or the key prop.

How do I derive state from props without useEffect?

Calculate the derived value directly during render, for example const fullName = firstName + ' ' + lastName. If the computation is expensive, wrap it in useMemo so it only recalculates when its dependencies change.

How do I reset component state when a prop changes?

Pass the changing prop as the key attribute on the component, such as <Profile userId={userId} key={userId} />. React treats different keys as different component instances and recreates all internal state automatically.

Why does my useEffect data fetch show stale results?

Missing cleanup causes race conditions where slower earlier responses overwrite newer ones. Add a cleanup function with an ignore flag or AbortController so stale responses are discarded when the dependency changes.

Why does useEffect run twice in development mode?

React 18 Strict Mode intentionally mounts components twice in development to expose missing cleanup. Add proper cleanup functions; for one-time app initialization, use a module-level guard variable instead.

What are alternatives to useEffect for external store subscriptions?

Use the useSyncExternalStore hook, which takes subscribe, getSnapshot, and optional server snapshot functions. It handles subscription lifecycle correctly and avoids tearing issues that manual Effect-based subscriptions can cause.