react-effects

Guide React developers on when to use useEffect for side effects.

2.0k|126|Updated Sep 17, 2025
One-click install
npx skills add https://github.com/coder/mux --skill react-effects-coder
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: react-effects
Source: https://github.com/coder/mux/tree/main/.mux/skills/react-effects
Command: npx skills add https://github.com/coder/mux --skill react-effects-coder

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

The guidelines help developers decide when to apply React's useEffect and when alternative approaches are more appropriate, reducing unnecessary side effects and rendering costs.

Core Features & Use Cases

  • Decision-tree guidance for common scenarios such as data fetching on mount, subscriptions, DOM interactions, and event handling
  • Clear identification of anti-patterns to avoid and recommended patterns for safe component lifecycles
  • Practical examples illustrating correct use of useEffect placement and cleanup

Quick Start

Read the decision tree and implement useEffect only for cases that involve external data, subscriptions, or DOM side effects.

Frequently Asked Questions about react-effects

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

FAQPage Schema
When should I use useEffect in React components?

Use useEffect in React components for synchronizing with external systems, including data fetching on mount, establishing subscriptions, and handling DOM interactions. Avoid it for transforming data or managing state derived from props to prevent unnecessary re-renders.

What are common useEffect anti-patterns to avoid?

Common useEffect anti-patterns include using it for derived state, chaining effects to propagate changes, and missing cleanup functions. These anti-patterns cause cascading re-renders and memory leaks in typical React applications.

How do I implement useEffect cleanup for subscriptions and event handling?

Implement useEffect cleanup by returning a function from the effect callback to cancel active subscriptions, remove event listeners, and clear timers. Reliable cleanup practices ensure predictable component lifecycles and prevent memory leaks during unmounting.

Does useEffect work with React hooks for data fetching?

Yes, useEffect works with React hooks for data fetching on component mount. Apply decision-tree guidance to fetch external data only when necessary, ensuring correct dependency arrays are specified to avoid duplicate network requests and unnecessary side effects.

Why does my useEffect cause infinite re-renders?

Your useEffect causes infinite re-renders when updating state inside the effect without proper dependency boundaries. Apply recommended patterns by verifying dependency arrays and avoiding state updates that trigger the same effect repeatedly.