react-use-activity
v0.1.0
Published
React hook that let's you react to user activity or inactivity
Downloads
8
Maintainers
Readme
react-use-activity
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 triggeronInactivity
- defaults to2000
onActivity
- a callback that is executed any time user activity is registeredonInactivity
- a callback that is executed when user is inactive for the specified timeoutactivityEvents
- a space delimited string specifying dom events that should be treated as user activity - defaults tomousemove
Running example
Use one of the following based on your dependency manager.
$ npm run start:example
$ yarn start:example
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.