Skip to main content

Command Palette

Search for a command to run...

useEffect Hook (infinte LOOP)

Updated
1 min readView as Markdown
useEffect Hook (infinte LOOP)

State updates → triggers re-render → state updates → triggers re-render → …

https://alexsidorenko.com/blog/react-infinite-loop/

if we would send a Http request for example, directly in the app. Then we would send this request whenever this function re-runs. So for example, whenever this state changes and that might sometimes be what you want but definitely not always.

And if in response to your Http request you for example eventually change some state, you would even create an infinite loop. Because : You would send the request whenever the function re-runs. And in response to the request you change some state which triggers this function again. So therefore such side effects should not go directly into this component function because that would most likely create bugs, infinite loops or simply send too many Http requests to stick with that example. Therefore we'll have a better tool for handling side effects and that's a special React Hook which we can use. The useEffect()Hook.

More from this blog

Omar's blog

135 posts