I’ve tried to implement a function that starts a count down when the isPlaying variable is truthy and it stops when it’s falsy, in general, it doesn’t work and all it does is just start multiple intervals simultaneously,
The isPlaying changes when the video stops or start playing again
let interval
useEffect(() => {
if (isPlaying) {
interval = setInterval(() => {
setTimePassed((time) => time + 1)
}, 1000);
} else {
console.log('clear interval');
clearInterval(interval);
}
return () => clearInterval(interval);
}, [isPlaying])