I\'m using a useEffect to show a UI Loading... but only after 250ms. It works ... but I really don\'t understand why and specially how and when useEffect invokes the returned fu
As per the react documentation,
Cleaning up an effect
The clean-up function runs before the component is removed from the UI to prevent memory leaks. Additionally, if a component renders multiple times (as they typically do), the previous effect is cleaned up before executing the next effect.
Timing of effects
React will always flush a previous render’s effects before starting a new update.
As per my understanding from both the quotes, cleanup runs after the effect is applied and before the component is unmounted (removed from UI).