fn
useIdle
v0.0.14testeddemoTrack whether the user has been inactive for a given duration.
Examples
ts
const { idle, lastActive, reset } = useIdle(5 * 60_000); // 5 minutests
const { idle } = useIdle(10_000, { events: ['keydown'] });Demo
Loading demo…
Signature
ts
export function useIdle(
timeout: number = ONE_MINUTE,
options: UseIdleOptions ={ ... }Parameters
| Parameter | Type | Description |
|---|---|---|
timeout? | number | Idle threshold in milliseconds |
options? | UseIdleOptions | Options |
Returns
UseIdleReturn{ idle, lastActive, isPending, reset, start, stop }| Property | Type | Description |
|---|---|---|
idle | ShallowRef<boolean> | Whether the user is currently idle |
lastActive | ShallowRef<number> | Timestamp (ms) of the last detected user activity |
isPending | Readonly<ShallowRef<boolean>> | Whether the idle tracker is currently running |
reset | () => void | Manually mark the user as active and restart the idle timer |
start | () => void | Begin (or resume) tracking. Restarts the idle timer unless initialState is true |
stop | () => void | Stop tracking. Resets idle to initialState and clears the pending timer |