Skip to content

useIdle ​

Hook that defines the logic when the user is idle

sensors
test coverage
Last changed: last month

Installation ​

Library
CLI
Manual
typescript
import { useIdle } from '@siberiacancode/reactuse';

Usage ​

typescript
const { idle, lastActive } = useIdle();

Demo ​

Api ​

Parameters

NameTypeDefaultNote
milliseconds?numberONE_MINUTEThe idle time in milliseconds
options.initialState?booleanfalseThe options for the hook
options.events?Array<keyof WindowEventMap>IDLE_EVENTS

Returns

UseIdleReturn

Type declaration ​

typescript
export interface UseIdleOptions {
  /** The idle events */
  events?: Array<keyof DocumentEventMap>;
  /** The idle state */
  initialValue?: boolean;
}

export interface UseIdleReturn {
  /** The idle state */
  idle: boolean;
  /** The last active time */
  lastActive: number;
}

Source ​

Source • Demo

Contributors ​

D
debabin
debabin
H
hywax
hywax

Released under the MIT License.