/react-use-activity

React hook that let's you react to user activity or inactivity

Primary LanguageJavaScriptMIT LicenseMIT

react-use-activity

build version downloads license

React hook that let's you react to user activity or inactivity

Installation

Use one of the two based on your project's dependency manager.

$ npm install react-use-activity --save

$ yarn add react-use-activity

Getting started

import useActivity from 'react-use-activity';

useActivity({
  timeout: 2000,
  onActivity: () => {},
  onInactivity: () => {},
  activityEvents: 'mousemove',
});

Arguments:

  • options
    • timeout - the duration (ms) of inactivity that should trigger onInactivity - defaults to 2000
    • onActivity - a callback that is executed any time user activity is registered
    • onInactivity - a callback that is executed when user is inactive for the specified timeout
    • activityEvents - a space delimited string specifying dom events that should be treated as user activity - defaults to mousemove

CodeSandbox example

https://codesandbox.io/s/lingering-glade-p1yun?file=/src/App.js

Licence

MIT © Mutai Mwiti | GitHub | GitLab

DISCLAIMER: All opinions expressed in this repository are mine and do not reflect any company or organisation I'm involved with.