# 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

```ts
import { useIdle } from '@vincent.ri/react-tils'
// or only this hook
import { useIdle } from '@vincent.ri/react-tils/useIdle'
```

## Usage

```ts
const idle = useIdle(5 * 60_000)
return idle ? <Dialog>Are you still there?</Dialog> : null
```

## 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

```ts
function useIdle(timeoutMs?: number): boolean
```

| Parameter | Description |
| --- | --- |
| `timeoutMs` | Milliseconds without activity before idle. Default `60_000`. |

## Browser support

Works in all modern browsers.

---

238 B minified and brotlied
Source: https://github.com/vincentri/react-tils/blob/main/src/useIdle.ts
Docs page: https://vincentri.github.io/react-tils/hooks/useIdle/
Previous: [useWindowFocus](https://vincentri.github.io/react-tils/hooks/useWindowFocus.md)
Next: [usePreferredLanguages](https://vincentri.github.io/react-tils/hooks/usePreferredLanguages.md)
