So I have been working on my 25+5 clock, and I basically have everything working I just need to clean up tests and add more styling but I am STRUGGLING with getting the audio to play once the timer reaches 00:00. I have tried doing useRef, where
function App() {
const audioElement = useRef(null);
and
audio id=“beep” src=“Beep.mp3” type=“audio/mpeg”
then within a useEffect:
useEffect(()=>{
if (timeLeft === 0 ){
audioElement.play();
if (currentSessionType === ‘Session’){
setCurrentSessionType(‘Break’)
setTimeLeft(breakLength)
} else if (currentSessionType === ‘Break’){
setCurrentSessionType(‘Session’)
setTimeLeft(sessionLength);
}
}
},[breakLength, currentSessionType, timeLeft, sessionLength, audioElement])
I have been toggling back and forth trying new things but I havent been able to properly implement anything. Can someone help explain this to me or suggest an alternate approach?