I am trying to dispatch an action every after 5 min. It has to dispatch action once user is logged in. It will start dispatching action every after 5min. I tried using setInterval
but the problem here is even if I am logout it keeps on dispatching action.
Here is My Code
I have defined this keepAlive function inside my app.js where I have wrapped whole app into redux store.
Here is isAuthenticated
is boolean function. If isAuthenticated
is true and API.getAcessToken
is available in localstorage
only then I want to dispatch action.
function keepAlive() {
if (
props.isAuthenticated === true &&
API.getAccessTokenFromLocalStorage()
) {
setInterval(() => {
props.keepTokenAlive();
}, 100000); // 1000ms =1sec
} else {
return null;
}
}
keepAlive();