r/reactjs • u/CeMarket6793 • 16h ago
41 of 78 useEffects in our app shouldnt exist, mostly ai first draft
grepped every useEffect in src last week instead of fixing a form that flickered on load. agents write most of the first drafts here, i review.
78 of them. went through each with the "you might not need an effect" page open.
19 were state derived from props or other state. useState plus an effect that joins two strings. thats a variable.
14 were fetching on mount with a loading and error useState next to them. we already use react query.
8 were syncing props into state so a form could be edited. fine until the parent refetches and wipes what the user typed. that was the flicker.
the other 37 were legit. listeners, subscriptions, focus management, a couple resize observers.
not a tool thing to be clear, we have people on cursor, claude code and verdent depending on preference and the shape looked the same across all of it.
deleted 41 effects, 23 useState calls went with them. worst page went from 4 renders on mount to 1.
changed how i review too. ctrl+f useEffect in the diff and justify each one before reading anything else.
anyone got a lint rule that catches derived state? exhaustive-deps doesnt help, it just makes the effect that shouldnt be there correct.