Skip to content

useIdle

Category
Export Size
761 B
Last Changed
5 days ago

Tracks whether the user is being inactive

Demo

Usage

tsx
import { 
useIdle
} from '@reause/core'
const {
idle
,
lastActive
,
reset
} =
useIdle
(5 * 60 * 1000) // 5 min
console
.
log
(
idle
) // true or false

reset() restarts the idle timer without touching lastActive.

Type Declarations

ts
export interface UseIdleOptions extends ConfigurableWindow {
    events?: (keyof WindowEventMap)[];
    listenForVisibilityChange?: boolean;
    initialState?: boolean;
    eventFilter?: EventFilter;
}

export interface UseIdleReturn {
    idle: boolean;
    lastActive: number;
    isPending: boolean;
    reset: () => void;
    stop: () => void;
    start: () => void;
}

export function useIdle(timeout?: number, options?: UseIdleOptions): UseIdleReturn

Source

Source · Demo · VueUse

Contributors

hairyf

Changelog

v0.1.0 on
4a3d4 - fix(core): resolve useIdle audit findings (#581)
55039 - fix(core): resolve useNow audit findings (#610)

Released under the MIT License. v0.1.8