Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

clearinterval in useEffect

let intervalID;
useEffect(() => {
    if (isRunning) {
      intervalID = setInterval(() => {
        dispatch({ type: "tic-toc" });
      }, 1000);
    }
      return () => clearInterval(intervalID);
  }, [isRunning]);
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #clearinterval #useEffect
ADD COMMENT
Topic
Name
2+4 =