A component starts a timer inside useEffect with an empty dependency array. In a development build with Strict Mode, setup appears twice. How can it keep only one active timer, and stop that timer when the component unmounts?
Editorial starter question from DevCircle, provided for learning and discussion.
Cleanup cancels the first timer before another setup and when the component unmounts. Do not hide the extra setup with a “has run” ref: that can conceal the leak. Subscriptions and event listeners need matching cleanup too.
Check: mount, unmount, and mount again. Only one timer should remain active.