In a React app, I created countdown timer:
const [showSec, setShowSec] = useState(15);
useEffect(() => {
const timer =
showSec > 0 && setInterval(() => setShowSec(showSec - 1), 1000);
if (showSec === 0) {
setShowEnterCode(false);
}
return () => clearInterval(timer);
}, [showSec]);
I show it like that:
<span>{showSec}</span>
and in another place in my code I have something like this for showing some errors:
{props.args.errorFormat === 2 ? (
<ErrorSnackBar args={ErrorSnackbarArgs} />
) : (
<></>
)}
But my problem is that, every time that countdown counts, this part of code executes again. It seems re rendering happens. for example when that condition is true, It should show an error with Material-UI's SnackBar but because of that countdown timer, it restart showing the error constantly. I cant prevent this issue. what I have to do?