As part of my react app, setInterval specific count-down is not works exactly with same seconds when the browser tab is either inactive or not focused scenario.
What the alternative or best solution to overcome this issue?
const [inactiveTimer, setInactiveTimer] = useState(120);
useEffect(() => {
const inactiveInterval = setInterval(() => {
if (timeoutInterval > 0) {
setInactiveTimer(timeoutInterval - 1);
} else if (timeoutInterval === 0) {
setShowModal(true);
}
}, 1000);
return () => {
clearInterval(inactiveInterval);
};
}, []);