Menu

1 / 2

Smell-checking AI-suggested React hooks before you merge

DEV Community: frontend·Sherotree·17 days ago
#YvhHEVHU
#devtofrontend#devto#dev#useeffect#smell
Reading 0:00
15s threshold

AI is weirdly confident about React hooks. Ask for “extract the data fetching into a custom hook” and you’ll get something that looks idiomatic: useSomething , a useEffect , a couple of useMemo s, maybe a useCallback for good measure. Types pass. The demo works once. Then you merge and discover the effect fires twice on every keystroke, or the cleanup never ran, or the hook is just a wrapper around three lines that didn’t need a name.

I treat AI-suggested hooks like AI-suggested refactors: useful drafts, not mergeable by default. Here’s the smell checklist I run before I accept the branch.

Smell 1: useEffect dependency lies

The model loves this pattern:

useEffect (() => { fetchUser ( userId ). then ( setUser ); }, []); // "run once on mount"

Enter fullscreen mode

Exit fullscreen mode

Except userId changed three routes ago, and the effect still holds the first id. Or the opposite lie:

useEffect (() => { analytics . track ( " view " , { id : item .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.