Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/toluade/usewindowinactivity

A react hook to get the inactivity state of a window.
https://github.com/toluade/usewindowinactivity

react-hooks reactjs typescript

Last synced: about 1 month ago
JSON representation

A react hook to get the inactivity state of a window.

Awesome Lists containing this project

README

        

# useWindowInactivity

A React hook that returns the inactivity state of a window.

### Props

- `delay: number`
- This is the amount of time (in seconds) it takes to return a positive inactive state.
- Default value is `5` seconds.

## inactive

```ts
const inactive = useWindowInactivity(5);
```

- `inactive: boolean`
- Returns `true` when the window is inactive after the number of seconds passed to the `useWindowInactivity` hook.
- Returns `false` when window is active.

## Install

npm

```sh npm
npm i @toluade/use-window-inactivity --save
```

yarn

```sh yarn
yarn add @toluade/use-window-inactivity
```

## Example Usage

```ts
import useWindowInactivity from "use-window-inactivity";

function App() {
const inactive = useWindowInactivity(5);

return (

{inactive ?

Window is inactive

:

Window is active

}

);
}
```