DIVYA PANDRAJU’s Post

⚛️ That moment when I realized useEffect() was watching everything I did 👀 When I first learned React, I used useState() like a pro... but then I needed to fetch data from an API. So naturally, I wrote it right inside my component: function App() { fetch("/api/data").then(...); return <h1>Hello</h1>; } And then React said: “Sure, let me fetch that again... and again... and again!” 😭 My console was spamming network requests like a DJ mixing beats. 🎧 That’s when I discovered useEffect() — the hook that runs side effects the right way. ✅ The correct way: useEffect(() => { fetch("/api/data").then(...); }, []); // runs only once 💡 Lesson learned: useEffect() lets you run side effects like fetching data, updating the DOM, or setting timers. The dependency array ([]) controls when it runs. Empty [] → runs once. Add variables → runs when they change. Now my app fetches data once, not forever. 🙌 React hooks aren’t just syntax — they’re patterns that teach us when and why things happen. 💭 #ReactJS #useEffect #ReactHooks #WebDevelopment #MERNStack #FrontendDeveloper #LearningByDoing #JavaScript #CodingJourney #ReactTips

To view or add a comment, sign in

Explore content categories