react-mouse-timer
v1.0.0
Published
React hook resolving if mouse has moved in previous period of time
Downloads
1
Maintainers
Readme
react-mouse-timer
React hook resolving if mouse has moved in previous period of time
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 seconsd!</p>}
{mouseMoved10 && <p>Mouse has moved in last 10 seconsd!</p>}
</div>
)
}
Parameters
ms : number
Default value: undefined
Number of previously elapsed milliseconds for checking mouse movement. Must be greater than 0