let intervalID;
useEffect(() => {
if (isRunning) {
intervalID = setInterval(() => {
dispatch({ type: "tic-toc" });
}, 1000);
}
return () => clearInterval(intervalID);
}, [isRunning]);
const Loading = () => {
const [loadingStatus, setLoadingStatus] = useState(".");
useEffect(() => {
const intervalId = setInterval(() => {
setLoadingStatus(ls => ls + ".");
}, 1000);
return () => clearInterval(intervalId);
}, []);
return <p>{`Loading ${loadingStatus}`}</p>;
};