Last active
January 4, 2021 18:11
-
-
Save sadewole/ad74845de5a1a9e16eb07b4049346cb1 to your computer and use it in GitHub Desktop.
last part for session timer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// reset interval timer | |
let resetTimer = useCallback(() => { | |
clearTimeout(startTimerInterval.current); | |
clearInterval(warningInactiveInterval.current); | |
if (isAuthenticated) { | |
timeStamp = moment(); | |
sessionStorage.setItem('lastTimeStamp', timeStamp); | |
} else { | |
clearInterval(warningInactiveInterval.current); | |
sessionStorage.removeItem('lastTimeStamp'); | |
} | |
timeChecker(); | |
}, [isAuthenticated]); | |
useEffect(() => { | |
events.forEach((event) => { | |
window.addEventListener(event, resetTimer); | |
}); | |
timeChecker(); | |
return () => { | |
clearTimeout(startTimerInterval.current); | |
}; | |
}, [resetTimer, events, timeChecker]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment