useIdle

Detect user inactivity with useIdle.

Install:

npm i @uidotdev/usehooks

Description:

The useIdle hook is a useful tool for detecting user inactivity within a web application. It tracks user interaction and determines if a specified duration of time has passed without any activity. This hook is particularly handy for implementing features like automatic logout, displaying notifications after a period of inactivity, or adjusting UI elements based on user engagement.

Parameters

NameTypeDescription
msnumberThis is the duration of idle time (in milliseconds) after which the idle state will be set to true. The default value is 20 * 1000 (20 seconds).

Return Values

NameTypeDescription
idlebooleanA boolean indicating if the user is idle. It is true if the user has been idle for at least ms milliseconds.

Demo:

Example:

More Hooks:

Sort: