Skip to content
Skillpedia
Websites & UI (frontend)33k Β· #8793

react-useeffect

What it does

This skill teaches your AI agent to use React's useEffect only when it is needed. It is for developers whose React code has effects that could be simpler.

When to use it

  • βœ“When you write or review a useEffect in a React component.
  • βœ“When state is being synced with useState and useEffect in a way that feels clumsy.
  • βœ“When you fetch data or reset state in React and want the cleanest approach.

Skill link

https://github.com/davila7/claude-code-templates/blob/main/cli-tool/components/skills/development/react-useeffect/SKILL.md

Copy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.

How to use

The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.

Ready-to-paste message

Use this skill to help me: https://github.com/davila7/claude-code-templates/blob/main/cli-tool/components/skills/development/react-useeffect/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute β†’

Example of what to ask your AI

β€œReview my React component and remove any useEffect calls that are not needed.”

5 new skills a week. 1 minute to read.

How it works

The agent checks each effect against a list of cases where Effects are not needed, such as derived values or event responses. It replaces them with simpler patterns like calculating during render or using event handlers.

Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

You Might Not Need an Effect

Effects are an escape hatch from React. They let you synchronize with external systems. If there is no external system involved, you shouldn't need an Effect.

Quick Reference

Situation DON'T DO
Derived state from props/state useState + useEffect Calculate during render
Expensive calculations useEffect to cache useMemo
Reset state on prop change useEffect with setState key prop
User event responses useEffect watching state Event handler directly
Notify parent of changes useEffect calling onChange Call in event handler
Fetch data useEffect without cleanup useEffect with cleanup OR framework

When You DO Need Effects

  • Synchronizing with external systems (non-React widgets, browser APIs)
  • Subscriptions to external stores (use useSyncExternalStore when possible)
  • Analytics/logging that runs because component displayed
  • Data fetching with proper cleanup (or use framework's built-in mechanism)

When You DON'T Need Effects

  1. Transforming data for rendering - Calculate at top level, re-runs automatically
  2. Handling user events - Use event handlers, you know exactly what happened
  3. Deriving state - Just compute it: const fullName = firstName + ' ' + lastName
  4. Chaining state updates - Calculate all next state in the event handler

Decision Tree

Need to respond to something?
β”œβ”€β”€ User interaction (click, submit, drag)?
β”‚   └── Use EVENT HANDLER
β”œβ”€β”€ Component appeared on screen?
β”‚   └── Use EFFECT (external sync, analytics)
β”œβ”€β”€ Props/state changed and need derived value?
β”‚   └── CALCULATE DURING RENDER
β”‚       └── Expensive? Use useMemo
└── Need to reset state when prop changes?
    └── Use KEY PROP on component

Detailed Guidance

FAQ

When is an Effect really needed?

It is needed to sync with external systems, such as browser APIs or subscriptions outside React.

What replaces an Effect for resetting state?

A key prop can reset a component's state when a prop changes.

What about data fetching?

Use an Effect with cleanup, or the framework's built-in data mechanism.

Details

Original description by the author

React useEffect best practices from official docs. Use when writing/reviewing useEffect, useState for derived values, data fetching, or state synchronization. Teaches when NOT to use Effect and better alternatives.

repo: davila7/claude-code-templates

Popularity

GitHub stars
33k
Ranking position
#8793
License
MIT
Updated
11/2/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills