@toluade/use-window-inactivity
v0.0.3
Published
A React hook that returns the inactivity state of a window.
Downloads
4
Maintainers
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
const inactive = useWindowInactivity(5);
inactive: boolean
- Returns
true
when the window is inactive after the number of seconds passed to theuseWindowInactivity
hook. - Returns
false
when window is active.
- Returns
Install
npm
npm i @toluade/use-window-inactivity --save
yarn
yarn add @toluade/use-window-inactivity
Example Usage
import useWindowInactivity from "use-window-inactivity";
function App() {
const inactive = useWindowInactivity(5);
return (
<div>{inactive ? <p>Window is inactive</p> : <p>Window is active</p>}</div>
);
}