An open API service indexing awesome lists of open source software.

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.

Awesome Lists containing this project

README

          

# use-active-detect

> hook for detecting when a user is active.

[![NPM](https://img.shields.io/npm/v/use-active-detect.svg)](https://www.npmjs.com/package/use-active-detect) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](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).