This section of my code is what controls the timer by switching it into break and session time but when the timer hits 0:00 and switches to break session, it fails to switch back to the normal session. the onBreak state fails to update in the set interval code don’t know why… Any help or suggestions?
link to the code: A Pen by Moro Owusu Afriyie (codepen.io)
will do the styling later
let interval = setInterval(()=>{
date = new Date().getTime();
if(date > nextDate){
setDisplayTime((prev) => {
if(prev<=0 && onBreak ==="break"){
setOnBreak("session");
console.log({onBreak}); // onBreak doesn't update but still get the old value.. don't really understand why any help?
return breakLength;
}
// this side of the code doesn't execute due to the onBreak state not updating
else if(prev<=0 && onBreak ==="session"){
setOnBreak("break");
console.log({onBreak})
return sessionLength;
}
return prev-1;
});
nextDate += second;
}
},30) //update it every 30 milliseconds