From bdbfe0a3eff11dbcb36066d5f81f28e66bad50f3 Mon Sep 17 00:00:00 2001 From: GloireMutaliko21 Date: Thu, 4 Jul 2024 19:02:36 +0200 Subject: [PATCH] fix: clearInterval from useEffect task tracking --- apps/web/app/hooks/features/useTimer.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/web/app/hooks/features/useTimer.ts b/apps/web/app/hooks/features/useTimer.ts index fd64d7950..432a452c1 100644 --- a/apps/web/app/hooks/features/useTimer.ts +++ b/apps/web/app/hooks/features/useTimer.ts @@ -364,12 +364,15 @@ export function useTimer() { }, [timerStatus, setTimerStatus, stopTimerQueryCall, taskId, updateLocalTimerStatus]); useEffect(() => { + let syncTimerInterval: NodeJS.Timeout; if (timerStatus?.running) { - const syncTimerInterval = setInterval(() => { + syncTimerInterval = setInterval(() => { syncTimer(); }, 60000); - return () => clearInterval(syncTimerInterval); } + return () => { + if (syncTimerInterval) clearInterval(syncTimerInterval); + }; }, [syncTimer, timerStatus]); // If active team changes then stop the timer