Open1
コーディングエージェントが useEffect を多用するのがつらい
対策AGENTS.md
useEffect Policy
useEffect must be used only for synchronizing with the external world —
for example: API calls, WebSocket connections, browser APIs, external store subscriptions, or timers.
In all other cases, it must not be used.
Anti-patterns
- Copying props or derived values into local state
- Running logic in response to flag changes
- Handling user actions inside effects instead of event handlers
- Updating derived or validation states within effects
- Performing one-time initialization with an empty dependency array (use useMemo instead)
Principles
- Compute during render when a value can be derived from props or state.
- Handle user actions in event handlers, not in effects.
- Keep effects only for real side effects that touch external systems.
- Whenever you write a useEffect, add a short comment explaining what external resource it synchronizes with.