Vize

idle

Default activity events.

Package @vizejs/composable/idle
Own the source vize lib pull composable:idle
Runtime exports DEFAULT_IDLE_EVENTS, useIdle
Gzip budget 1792 B

Usage

import { DEFAULT_IDLE_EVENTS, useIdle } from "@vizejs/composable/idle";

Runtime contract

Utility Category Stability SSR Hydration Cleanup Targets Host globals Uses
useIdle system experimental deterministic-fallback stable reactive-scope web, desktop globalThis, window tryOnScopeDispose

API

DEFAULT_IDLE_EVENTS

Default activity events.

const DEFAULT_IDLE_EVENTS

useIdle

Detect user inactivity. Any configured activity event resets a single timer; when it fires, idle becomes true until the next activity. No timer runs during server rendering (idle is initialState, lastActive is null), so the output is hydration-stable. Listeners and the timer are released with the owning reactive scope.

function useIdle(timeout = 60_000, options: UseIdleOptions = {}): IdleControls

Types

IdleHost

Window-like capability observed by useIdle.

Member Type Description
document? EventTarget & { readonly hidden?: boolean } Document whose visibility changes count as activity when it becomes visible.

UseIdleOptions

Options for useIdle.

Member Type Description
events? readonly string[] Window events that count as activity.
listenForVisibilityChange? boolean Treat the document becoming visible again as activity.
initialState? boolean Idle state exposed during server rendering and before the timer starts.
now? () => number Clock used for lastActive.
scheduler? TimeoutScheduler Owns the idle timer.
host? MaybeRefOrGetter<IdleHost | null | undefined> Reactive window capability for alternate runtimes and tests.

IdleControls

Reactive idle state returned by useIdle.

Member Type Description
idle Readonly<Ref<boolean>> Whether no activity happened within the timeout.
lastActive Readonly<Ref<number | null>> Epoch milliseconds of the latest activity; null until tracking starts on the client.
reset () => void Record activity now and restart the timer. No-op until tracking starts on the client.