react-activity-detector
Version:
React Activity Detector. Detects if the user is active or idle, also includes Cross-Tab functionality
42 lines (30 loc) • 1.52 kB
Markdown
//img.shields.io/npm/v/react-activity-detector)](https://www.npmjs.com/package/react-activity-detector)
[]((LICENSE))
[](https://github.com/filipjelic/react-activity-detector/actions)
```
$ npm install --save react-activity-detector
```
```javascript
import ActivityDetector from 'react-activity-detector';
const customActivityEvents = [
'click',
'keydown',
];
const onIdle = () => {
console.log("The user seems to be idle...");
}
const onActive = () => {
console.log("The user is active!");
}
<ActivityDetector activityEvents={customActivityEvents} enabled={true} timeout={5*1000} onIdle={onIdle} onActive={onActive} name="default"/>
```
- `enabled`: Boolean value indicating if the A.D. is enabled.
- `timeout` time in milliseconds which will trigger `onIdle`
- `activityEvents`: events used to detect if the user is active. Default list of Activity Events is `['click', 'mousemove', 'keydown', 'DOMMouseScroll', 'mousewheel', 'mousedown', 'touchstart', 'touchmove', 'focus']`. If none event is sent the list will consume the default one.
- `name`: in need of multiple Activity Detectors, provide a custom name. Default value is `default`.
[![npm](https: