Ask what the effect synchronises, not how to fix it.
frontend
react
hooks
refactoring
Keywords:
useEffect
derived state
react refactor
When an effect misbehaves, the instinct is to paste it and ask "why does this run twice". You get an answer about StrictMode and you are no wiser.
Better prompt:
"For each effect in this component, tell me: what external system it synchronises with, what its cleanup should be, and whether it could be derived state or an event handler instead. Then rewrite only the ones that are genuinely effects."
The framing does the work. Most effects in a struggling component are not effects — they are derived values that got written as effects, and the rewrite deletes them rather than fixing them.
I ran this over a 400-line dashboard component. Six effects went to two, and the double-render bug disappeared on its own because the offending effect no longer existed.
Attachments (1)
4.4k5
Generated Outputs (1)
1 weeks ago
Claude
claude-opus-4
1 weeks ago
Generated Output
Effect 1 — syncs nothing external; filteredRows is derivable from rows + query. Delete, compute during render. Effect 2 — syncs nothing; runs on submit. Move into the submit handler. Effect 3 — genuine: subscribes to a WebSocket. Keep, add the missing close() in cleanup.
Comments (5)
No comments yet. Be the first to share your thoughts!
Top Contributors
Loading...
Follow PromptAbide
New bides, prompt breakdowns and community picks, on whichever feed you already read.
Trending Tags
Loading...
The Prompt I Use To Untangle useEffect | PromptAbide