Agent Skillssoftaworks/agent-toolkit › react-useeffect

react-useeffect

GitHub

提供 React useEffect 最佳实践,指导何时使用或避免副作用。涵盖派生状态、数据获取及替代方案如 useMemo,旨在优化组件逻辑并减少不必要的 Effect 使用。

skills/react-useeffect/SKILL.md softaworks/agent-toolkit

Trigger Scenarios

编写或审查 useEffect 代码 处理派生值、数据获取或状态同步

Install

npx skills add softaworks/agent-toolkit --skill react-useeffect -g -y
More Options

Use without installing

npx skills use softaworks/agent-toolkit@react-useeffect

指定 Agent (Claude Code)

npx skills add softaworks/agent-toolkit --skill react-useeffect -a claude-code -g -y

安装 repo 全部 skill

npx skills add softaworks/agent-toolkit --all -g -y

预览 repo 内 skill

npx skills add softaworks/agent-toolkit --list

SKILL.md

Frontmatter
{
    "name": "react-useeffect",
    "description": "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."
}

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

Version History

  • 3027f20 Current 2026-08-20 07:06

Same Skill Collection

skills/agent-md-refactor/SKILL.md
skills/backend-to-frontend-handoff-docs/SKILL.md
skills/c4-architecture/SKILL.md
skills/codex/SKILL.md
skills/command-creator/SKILL.md
skills/commit-work/SKILL.md
skills/crafting-effective-readmes/SKILL.md
skills/daily-meeting-update/SKILL.md
skills/database-schema-designer/SKILL.md
skills/datadog-cli/SKILL.md
skills/dependency-updater/SKILL.md
skills/design-system-starter/SKILL.md
skills/difficult-workplace-conversations/SKILL.md
skills/domain-name-brainstormer/SKILL.md
skills/draw-io/SKILL.md
skills/excalidraw/SKILL.md
skills/feedback-mastery/SKILL.md
skills/frontend-to-backend-requirements/SKILL.md
skills/game-changing-features/SKILL.md
skills/gemini/SKILL.md
skills/gepetto/SKILL.md
skills/jira/SKILL.md
skills/lesson-learned/SKILL.md
skills/marp-slide/SKILL.md
skills/meme-factory/SKILL.md
skills/mui/SKILL.md
skills/naming-analyzer/SKILL.md
skills/openapi-to-typescript/SKILL.md
skills/perplexity/SKILL.md
skills/plugin-forge/SKILL.md
skills/professional-communication/SKILL.md
skills/qa-test-planner/SKILL.md
skills/react-dev/SKILL.md
skills/reducing-entropy/SKILL.md
skills/requirements-clarity/SKILL.md
skills/ship-learn-next/SKILL.md
skills/skill-judge/SKILL.md
skills/web-to-markdown/SKILL.md
skills/writing-clearly-and-concisely/SKILL.md
skills/humanizer/SKILL.md
skills/mermaid-diagrams/SKILL.md
skills/session-handoff/SKILL.md

Metadata

Files
0
Version
3027f20
Hash
f31e9925
Indexed
2026-08-20 07:06

- 위키
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-25 07:37
浙ICP备14020137号-1 $방문자$