Awesome question π! To get started using the useActivityMonitor
hook, all you need to provide an object
with
timeout
-number
(in milliseconds,)events
- an optional array of case sensitive event names asstring
defaults to["load", "mousemove", "mousedown", "click", "scroll", "keypress"]
,onKillSession
- an optional callback function which will be called after the user invokes thekillSession
handler.
const { promptUser, restoreSession, killSession } = useActivityMonitor({
timeout: 1000 * 5, // 5 seconds
onKillSession: () => alert("You've been terminated! π€")
});
useActivityMonitor
returns three useful properties - promptUser
, restoreSession
, and killSession
promptUser
is aboolean
that indicates if the providedtimeout
(ms) has passed.restoreSession
is a callback function that will setpromptUser
tofalse
and reset the internal timer.killSession
is a callback function that will also setpromptUser
tofalse
but kill the internal timer completely.