Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/toluade/usewindowinactivity
- Owner: Toluade
- Created: 2024-04-05T18:46:02.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-04-22T15:23:05.000Z (10 months ago)
- Last Synced: 2024-12-29T07:13:03.965Z (about 1 month ago)
- Topics: react-hooks, reactjs, typescript
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@toluade/use-window-inactivity
- Size: 8.79 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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
}
);
}
```