Answers for "clearinterval react useeffect"

3

clearinterval in useEffect

let intervalID;
useEffect(() => {
    if (isRunning) {
      intervalID = setInterval(() => {
        dispatch({ type: "tic-toc" });
      }, 1000);
    }
      return () => clearInterval(intervalID);
  }, [isRunning]);
Posted by: Guest on May-30-2021
0

useeffect clearinterval loading

const Loading = () => {
  const [loadingStatus, setLoadingStatus] = useState(".");

  useEffect(() => {
    const intervalId = setInterval(() => {
      setLoadingStatus(ls => ls + ".");
    }, 1000);

    return () => clearInterval(intervalId);
  }, []);

  return <p>{`Loading ${loadingStatus}`}</p>;
};
Posted by: Guest on October-13-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language