So, when we use useEffect without a dependancy array, it happens on every render.
But that's what would happen if I just wrote the code directly into the component. So is there a reason to use it?
One thing I can think of is doing something with the cleanup function, but I can't think up a valid usecase.
But that's what would happen if I just wrote the code directly into the componentis not correct.useEffectfunctions run AFTER a render, not DURING.setTimeoutand then runclearTimeoutin the cleanup function (which takes effect when the component unmounts). The official React docs show another example: reactjs.org/docs/hooks-effect.html#effects-with-cleanup