Skip to content

React hook resolving if mouse has moved in previous period of time

License

Notifications You must be signed in to change notification settings

yh54321/react-mouse-timer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-mouse-timer

React hook resolving if mouse has moved in previous period of time

npm version

Usage Example

import useMouseTimer from 'react-mouse-timer';

function MyComponent () {
  const mouseMoved3 = useMouseTimer(3000); // 'true' if mouse moved in last 3 seconds
  const mouseMoved10 = useMouseTimer(10000); // This is safe, hook can be used multiple times without creating needless event listeners + timers, even across files + components
  
  return (
    <div>
      {mouseMoved3 && <p>Mouse has moved in last 3 seconds!</p>}
      {mouseMoved10 && <p>Mouse has moved in last 10 seconds!</p>}
    </div>
  )
}

Parameters

ms : number

Default value: undefined

Number of previously elapsed milliseconds for checking mouse movement. Must be greater than 0