Last active
January 5, 2021 12:39
-
-
Save sadewole/49c771686f2e14e4d4f74adfa92e02f0 to your computer and use it in GitHub Desktop.
initial function
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
const SessionTimeout = () => { | |
const [events, setEvents] = useState(['click', 'load', 'scroll']); | |
const [second, setSecond] = useState(0); | |
// reset interval timer | |
let resetTimer = useCallback(() => { | |
if (isAuthenticated) { | |
timeStamp = moment(); | |
sessionStorage.setItem('lastTimeStamp', timeStamp); | |
} else { | |
sessionStorage.removeItem('lastTimeStamp'); | |
} | |
}, [isAuthenticated]); | |
// Life cycle hook | |
useEffect(() => { | |
events.forEach((event) => { | |
window.addEventListener(event, resetTimer); | |
}); | |
}, [resetTimer]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment