🚀 React Developers — Can you answer this tricky questions? This look simple, but they test deep understanding of React’s rendering cycle, batching, and hooks. 👉 Many devs say “it increases count by 1,” but React will actually re-render endlessly. ✅ Why? Because the effect depends on count, and inside the effect we update count. Each update triggers the effect again → causing an infinite loop 🔁 #reactjs #frontenddevelopment #javascript #reacthooks #reactinterview #webdevelopment #nextjs #reacttips #frontendengineer #seniorfrontend #programming #womenintech #softwaredevelopment #developers #codingtips #learnreact
Yes, this code will cause an infinite loop. Explanation: useEffect runs every time count changes. Inside the effect, you call setCount(count + 1), which updates count. The update triggers another render, which triggers useEffect again, and so on. Result: The component will keep re-rendering and incrementing count forever, causing an infinite loop and eventually crashing the app.
I think trick here is that, someone could think that direct setting of count will get same count value on next render and hence use effect will not be called again. But thats not true, ultimately setcount is going to update count to 1 and component is going to re render. Hence re rendering will have updated count (1), so again use effect will continue and an infinite loop will he formed.