iwakoscott / activityHook

Created with CodeSandbox

Home Page:https://codesandbox.io/s/github/iwakoscott/activityHook

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

useActivityMonitor Hook! πŸ‘€

How do I use useActivityMonitor?

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 as string defaults to ["load", "mousemove", "mousedown", "click", "scroll", "keypress"],
  • onKillSession - an optional callback function which will be called after the user invokes the killSession 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 a boolean that indicates if the provided timeout (ms) has passed.
  • restoreSession is a callback function that will set promptUser to false and reset the internal timer.
  • killSession is a callback function that will also set promptUser to false but kill the internal timer completely.

About

Created with CodeSandbox

https://codesandbox.io/s/github/iwakoscott/activityHook


Languages

Language:JavaScript 65.4%Language:HTML 33.3%Language:CSS 1.3%