avoid-effects

Identify when to use React useEffect versus event handlers or render.

Updated Nov 26, 2025
One-click install
npx skills add https://github.com/Aias/dotfiles --skill avoid-effects
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: avoid-effects
Source: https://github.com/Aias/dotfiles/tree/main/agents/skills/avoid-effects
Command: npx skills add https://github.com/Aias/dotfiles --skill avoid-effects

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

React code often relies on useEffect to manage a wide range of side effects, causing unnecessary renders, stale state, and convoluted data flow. This Skill helps you distinguish when an effect is truly needed and how to move logic into event handlers or render paths to keep components predictable.

Core Features & Use Cases

  • Clarifies when to use useEffect for external sync (fetching data, subscriptions, analytics) and when to handle logic in events or during rendering.
  • Provides patterns to avoid derived state inside effects, implement proper cleanup, and cancel asynchronous tasks.
  • Covers common scenarios such as prop changes, conditional effects, and avoiding chain-reaction updates by consolidating logic in handlers.

Quick Start

Refactor a component that uses an effect for data fetch on mount so that the fetch is triggered by a user action and all derived state is computed in render.

Frequently Asked Questions about avoid-effects

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

FAQPage Schema
When should I use useEffect versus event handlers in React?

You should avoid useEffect for derived state and instead compute values directly during render, which prevents convoluted data flow, unnecessary chain-reaction updates, and stale state inside your React components.

How do I cancel asynchronous tasks and implement cleanup in React effects?

Cancel asynchronous tasks and implement cleanup inside useEffect by returning a cleanup function, ensuring active subscriptions and fetch requests are safely terminated to avoid memory leaks.

Why does using useEffect for prop changes cause chain-reaction updates?

Using useEffect for prop changes causes chain-reaction updates because syncing props to state inside effects creates redundant render cycles, so you should consolidate this logic in event handlers instead.

What is the best way to handle analytics side effects in React?

The best way to handle analytics side effects is using useEffect for external system synchronization, ensuring events fire predictably without interfering with component rendering or derived state.

Can I move data fetching logic from useEffect to event handlers?

Yes, you can move data fetching logic from useEffect to event handlers when the fetch is triggered by a user action, keeping derived state computed in render for predictable components.