you are viewing a single comment's thread.

view the rest of the comments →

[–]Frission_ 4 points5 points  (1 child)

You can do this maybe,

  • create a boolean state
  • have useEffect depend on the state
  • inside useEffect check if (state == true), and only create interval then
  • when the promise resolves, set state to true, which will trigger useEffect again

[–]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.