@toluade/use-window-inactivity
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

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 the useWindowInactivity hook.
    • Returns false when window is active.

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>
  );
}

Package Sidebar

Install

npm i @toluade/use-window-inactivity

Weekly Downloads

0

Version

0.0.3

License

MIT

Unpacked Size

15.9 kB

Total Files

5

Last publish

Collaborators

  • tolu-ade