https://github.com/yyz945947732/use-active-detect
hook for detecting when a user is active.
https://github.com/yyz945947732/use-active-detect
active activity detect idle interaction react react-hook
Last synced: about 1 month ago
JSON representation
hook for detecting when a user is active.
- Host: GitHub
- URL: https://github.com/yyz945947732/use-active-detect
- Owner: yyz945947732
- License: mit
- Created: 2023-09-09T06:49:22.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2023-09-09T16:50:19.000Z (almost 3 years ago)
- Last Synced: 2024-10-16T09:31:06.012Z (over 1 year ago)
- Topics: active, activity, detect, idle, interaction, react, react-hook
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/use-active-detect
- Size: 398 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# use-active-detect
> hook for detecting when a user is active.
[](https://www.npmjs.com/package/use-active-detect) [](https://standardjs.com)
## Install
```bash
npm install --save use-active-detect
```
## Usage
### useActiveDetect
```typescript
function useActiveDetect(options: Options): void;
```
##### Example
```tsx
import * as React from 'react';
import { useActiveDetect } from 'use-active-detect';
const Example = () => {
useActiveDetect({
onActive: () => {
console.log('active');
},
});
return
...;
};
```
### Options
| option | default | Description |
| -------- | --------- | ------------------------------------------ |
| onActive | () => {} | Function to call when user becomes active. |
| wait | 1000 * 30 | The number of milliseconds to delay. |
| element | document | Element to bind activity listeners to. |
##### Example
```tsx
useActiveDetect({
onActive: (event) => {
console.log(event);
},
wait: 1000,
element: document.body,
});
```
## License
MIT © [https://github.com/yyz945947732/use-active-detect](https://github.com/yyz945947732/use-active-detect/blob/master/LICENSE)
---
This hook is created using [create-react-hook](https://github.com/hermanya/create-react-hook).