All hooks / Page, device, and user
useIdle
Whether the user has been inactive (no pointer, keyboard, touch, wheel, or scroll input) for timeoutMs. Becomes false again on the next activity.
false on the server, during hydration, and on mount: a user who just loaded the page counts as active. Activity only records a timestamp, and a single timer checks it, so mouse movement does not re-render.
Import
import { useIdle } from '@vincent.ri/react-tils'
// or only this hook
import { useIdle } from '@vincent.ri/react-tils/useIdle'Usage
const idle = useIdle(5 * 60_000)
return idle ? <Dialog>Are you still there?</Dialog> : nullLive demo
Don't touch anything for 3 seconds.
When to use it
Showing "Are you still there?" before a session timeout, pausing expensive live updates, or setting a chat status to "away".
When not to
You mean "the tab is hidden"; use useDocumentVisibility. Activity inside an <iframe> (an embedded video or payment form) isn't seen, so a user busy there can turn idle. Don't use it alone to log users out for security; enforce session expiry on the server.
API
function useIdle(timeoutMs?: number): boolean| Parameter | Description |
|---|---|
timeoutMs | Milliseconds without activity before idle. Default 60_000. |
Browser support
| Uses | Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS |
|---|---|---|---|---|---|---|
| Pointer eventsWidely available | 55+ | 12+ | 59+ | 13+ | 55+ | 13+ |
| Touch eventsoptionalLimited availability | 22+ | 12+ | 52+ | ✕ | 25+ | ≤3+ |
| wheel eventoptionalLimited availability | 31+ | 12+ | 17+ | 7+ | 31+ | ✕ |
Optional features are used when present; without them the hook still works.
First version with support, from MDN's compatibility data (web-features 3.42.0, @mdn/browser-compat-data 8.1.5).