Skip to content

Toluade/useWindowInactivity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published