react-useeffect
Audit React components for unnecessary useEffect hooks. Use when reviewing code that has useEffect, useState patterns, or when asked to optimize React components. Identifies anti-patterns like derived state, chained effects, event-driven effects and suggests better alternatives (computed values, useMemo, key prop, event handlers, useSuspenseQuery).
安装与使用
请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。
查看来源 ↗使用指南技能说明
React useEffect Best Practices
Effects are escape hatches - they should primarily synchronize with external systems. Many common use cases don't actually require Effects.
Key Recommendations
Avoid Effects for:
- Computing derived values (calculate during render instead)
- Handling user interactions (use event handlers)
- Managing state chains (compute state in handlers)
- Responding to prop changes (use the
keyprop)
Use Effects for:
- Synchronizing with external systems (non-React widgets, browser APIs)
- Subscriptions and analytics
- Data fetching with proper cleanup
The Decision Framework
Ask yourself: Is this responding to a user interaction (event handler), component appearance (effect), prop/state change needing derivation (calculate during render), or prop-based reset (key prop)?
This approach reduces unnecessary Effects, improving performance and maintainability.
Additional Resources
- anti-patterns.md - Common mistakes to avoid
- alternatives.md - Better solutions for each anti-pattern
使用示例
查看来源仓库中的使用示例与配置说明。
查看来源 ↗来源历史
- 收录时间
- 2026-01-20
- 索引更新时间
- 2026-02-04
- Branch
- main
收录与同步日期属于本站记录。源码修改历史请查看来源仓库。
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!