useEffect with no dependency array will run at the first render and after every render. It's used when we might want to run some code on every single render, although this scenario isn't used a lot.
No it won't go in a state of infinite loop unless you are changing any state values inside useEffect, in that case:
state change -> useEffect triggered -> state change -> ....goes on in an infinte loop
That's executed before the next useEffect, for example if you set a timeout inside useEffect, you must cancel it as return callback, so in the next execution, before setting the new timeout, the previously one is good to be cleared
useEffect with no dependency array will run at the first render and after every render. It's used when we might want to run some code on every single render, although this scenario isn't used a lot.
No it won't go in a state of infinite loop unless you are changing any state values inside useEffect, in that case:
state change -> useEffect triggered -> state change -> ....goes on in an infinte loop
And one more doubt, why return a call back method inside the useEffect?
That's executed before the next useEffect, for example if you set a timeout inside useEffect, you must cancel it as return callback, so in the next execution, before setting the new timeout, the previously one is good to be cleared
Empty array means only execute after mount. The value in the arrays is what react check for execution. Empty array means nothing to check
Hi Larrieu, I was referring to the scenario when we dont give a dependency array. 🙂