useIdle
Detects user inactivity after a specified timeout by listening to user interaction events.
Installation
bash
npx kuro-ui add useIdlebash
npx github:Bartek-Nowak/Kuro add useIdleUsage
ts
import { useIdle } from '@/composables/kuro/useIdle';
const { isIdle } = useIdle(300000); // default 5 minutes timeoutBind logic based on the isIdle ref to react when the user is idle or active.
API
| Name | Type | Description |
|---|---|---|
| timeout | number | Optional. Time in milliseconds before marking idle. Default is 300000 (5 minutes). |
| isIdle | Ref<boolean> | Reactive boolean indicating if the user is currently idle. |
Details
Listens for the following user events to reset the idle timer:
mousemovekeydownwheeltouchstart
Resets the idle timer on any of these events.
Sets
isIdletotrueif no user interaction happens within the timeout period.Cleans up event listeners on component unmount.