0
Why is useEffect(() => { setState(...) }, [state]) often a bug?
subina kallyani
medium
1completed
44
Answer
This creates a render loop: setting state in useEffect that depends on that state retriggers the effect → infinite updates.
Instead:
- Use conditional checks inside the effect.
- Or restructure logic with
useMemo/useCallback. - For derived state, calculate it directly during render instead of syncing with
useEffect.
Click to Reveal Answer
Tap anywhere to see the solution
Revealed
Comments0