JSFiddle - React, Tailwind, and code Playground
JavaScript
onInactive(5000, function(){
alert('Inactive for 5 seconds');
});
function onInactive(ms, cb){
var wait = setTimeout(cb, ms);
document.onmousemove = document.mousedown = document.mouseup = document.onkeydown = document.onkeyup = document.focus = function(){
clearTimeout(wait);
wait = setTimeout(cb, ms);
};
}