useIdle
React sensor hook that tracks if user on the page is idle
Usage
Live Editor
function Demo() { const isIdle = useIdle(3e3); return ( <div> <div>User is idle: {isIdle ? "Yes 😴" : "Nope"}</div> </div> ); };
Result
Loading...
API
UseIdle
Returns
boolean
: whether user is idle
Arguments
Argument | Description | Type | DefaultValue |
---|---|---|---|
ms | detection time | number | undefined | 60e3 |
initialState | initial value | boolean | undefined | false |
events | listener events | (keyof WindowEventMap)[] | undefined | ["mousemove","mousedown","resize","keydown","touchstart","wheel"] |