React useEffect infinite loop: Fixing a common mistake

🚀 30 Days — 30 Coding Mistakes Beginners Make Day 8/30 My backend server CPU suddenly went high 🔥 The reason? A simple `useEffect`. I wrote an API call inside `useEffect`… and forgot the dependency array. By default, `useEffect` runs after EVERY render. Inside it I was updating state → which caused another render → which called the API again. Infinite request loop. Fix 👇 useEffect(() => { fetchUsers(); }, []) Empty dependency array = run only once on mount. Small brackets. Huge difference. Day 9 tomorrow 👀 #30DaysOfCode #reactjs #javascript #frontend #webdevelopment #codeinuse

  • graphical user interface, application

To view or add a comment, sign in

Explore content categories