I want to setInterval again and again in react. I want to check if user is active on the page or not. if he is typing then I can make him active and if not then I can close the connection.
CodePudding user response:
You can use setTimeOut() for check user typing.
useEffect(() => {
let timeout;
refInput.current.addEventListener('keypress', () => { /* user is typing */
if (timeout) clearTimeout(timeout);
userIsActive();
timeout = setTimeout(() => {
userIsNotActive();
}, 30000 /* 30 second */);
});
}, []);