DEV Community

Discussion on: How to Create a Simple React Countdown Timer

Collapse
 
ankit_choudhary profile image
ankit kumar

hi @zhiyueyi , let me know your thoughts about this.

React.useEffect(() => {
const TimerInt = timer >0 && setInterval(() => {
setCounter((time)=>time-1);
}, 1000);
return () => {
clearInterval(TimerInt)
}
}, [timer]);