Not sure how I feel about this, but from my understanding, useEffect runs the cleanup function before each run of the effect, not just when the component updates. So, passing an empty array to the useEffect will make sure it's only set to false on unmount instead of flipping it between renders.
Not sure how I feel about this, but from my understanding,
useEffectruns the cleanup function before each run of the effect, not just when the component updates. So, passing an empty array to theuseEffectwill make sure it's only set to false on unmount instead of flipping it between renders.I'm wondering why not an empty array too.
I did the same
useMountedRefhook but with an empty array usage and it change not a thing. So yes, I would also prefer that way IMHO.