Missing dependency array in useEffect caused infinite API calls.

⚛️ A real-life React situation that taught me a valuable lesson! I was fetching data from an API inside my React component. Everything worked fine at first — until I noticed something strange… the API was being called again and again 😅 My first thought: “Is my API haunted?” 👻 Turns out, it was just me forgetting to add the dependency array in useEffect. Here’s what I learned 👇 ❌ Wrong: useEffect(() => { fetchData(); }); ✅ Correct: useEffect(() => { fetchData(); }, []); The empty [] tells React to run the effect only once when the component mounts — not after every render. Lesson learned: sometimes one missing pair of brackets can cause infinite chaos 😆 Every mistake in React makes me understand it better — one re-render at a time! 🚀 #ReactJS #MERNStack #FrontendDevelopment #WebDevelopment #CodingJourney #LearningByDoing

To view or add a comment, sign in

Explore content categories