React Bug Hunt Hard +35 XP
Infinite Loop
This component re-renders infinitely.
ReactFind the bug
1
useEffect(() => {2
setData(fetchData());3
}); The bug is on line 2
Select the correct fix
Show answer and explanation
Answer: Add empty dependency array []
Without a dependency array, useEffect runs after every render. Setting state triggers a render, causing infinite loops.
Hint: When does this effect run without a dependency array?
What this challenge tests
Bug Hunt in React: hooks, useEffect, bugs.