DEV Community

Discussion on: How to create a countdown timer using React Hooks

Collapse
 
pablowbk profile image
Pablo

Hi Tapas! Great article, it's helped me a lot with a countdown feature I'm currently implementing. Wanted to ask, once the timer is expired, is the interval still running? how would you go about stopping its execution as soon as the countdown reached zero? Thanks a lot for your time and effort

Collapse
 
atapas profile image
Tapas Adhikary

Hi Pablo,

yes the timer keeps runnig if we are not clearing it. As you see we are using the cleanup function in the useEffect hook to take care of it

return () => clearInterval(interval);
Enter fullscreen mode Exit fullscreen mode

The moment you call the clearInterval(interval); with the respective intervalID you can control the timer. So you can call it based on your use cases.

Thanks for giving it a read and commenting.

Collapse
 
pablowbk profile image
Pablo

NIce, thanks a lot!