useIdle
React hook to detect user inactivity, track idle status, and trigger callbacks on idle and active state changes.
Demo
Active3s inactivity threshold
Move your mouse or press a key...
Usage
Simple — single callback fires when the user goes idle:
Object form — separate idle/active callbacks with custom events:
Parameters
| Parameter | Type | Description |
|---|---|---|
timeout | number | Inactivity duration in ms before onIdle fires. |
callback | () => void | Simple form. Fires once when the user becomes idle. |
Object form second argument:
| Property | Type | Default | Description |
|---|---|---|---|
onIdle | () => void | — | Fires when the user has been inactive for timeout ms. |
onActive | () => void | — | Fires when the user interacts again after being idle. |
events | string[] | ['mousemove', 'mousedown', 'keydown', 'touchstart', 'wheel', 'pointermove'] | DOM events that reset the idle timer. |
Return Values
Returns isIdle: boolean — true while the user is idle.