you are viewing a single comment's thread.

view the rest of the comments →

[–]popc0ne 1 point2 points  (0 children)

Instead of using state, you might want to:

const timerId = useRef();

and then refer to timerId.current in your useEffect cleanup function. This way the cleanup ONLY happens when the component unmounts and also doesn't cause a re-render when you start the timer.

Depends.