we are a community of more than 2 million smartest coders
registration for
employee referral programs
are now open
get referred to google, amazon, flipkart and more
register now
  
pinned-register now
showing results for - "clearinterval in useeffect"
Maximiliano
18 Mar 2020
1let intervalID;
2useEffect(() => {
3    if (isRunning) {
4      intervalID = setInterval(() => {
5        dispatch({ type: "tic-toc" });
6      }, 1000);
7    }
8      return () => clearInterval(intervalID);
9  }, [isRunning]);
10