When does the cleanup function returned by useEffect run?
React runs an Effect's cleanup function before running that Effect again when its dependencies have changed, and one final time when the component unmounts. In development, Strict Mode also runs an extra setup-and-cleanup cycle to help reveal bugs.