Advertisement
Shell_Casing

setInterval

May 17th, 2021
963
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. let intervalID = 0;
  3.  
  4. useEffect(() => {
  5.     intervalID = setInterval(() => dispatch(eventsAction(jiraCode)), 5000);
  6.     if(finished) {
  7.         clearInterval(intervalID);
  8.     }
  9. }, [finished]);
  10.  
  11. useEffect(() => {
  12.     if(tableData?.length && (tableData[0]['status'] === 'POD:COMPLETE' || tableData[0]['status'] === 'POD:FAILED')) {
  13.         clearInterval(intervalID);
  14.         setFinished(true);
  15.     }
  16. }, [tableData]);// eslint-disable-line react-hooks/exhaustive-deps
  17.  
  18. // clear errors
  19. useEffect(() => {
  20.     dispatch(clearErrorsAction());
  21.     return () => clearInterval(intervalID);
  22. }, []);// eslint-disable-line react-hooks/exhaustive-deps
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement