Detecting when the user becomes inactive (idle) or active.
npm install --save @react-corekit/use-idle
yarn add @react-corekit/use-idle
import React from "react";import useIdle from "@react-corekit/use-idle";const Example =const options = timeToIdle: 1000 ;const isIdle = ;return <div>isIdle ? "Are you still there?" : "Yes, you are here"</div>;;
mousemove event is ignored by default, to include it add the following line to the options object:
const options = ignoredEventsWhenIdle: ;
Activity detector allows you to configure some parameters:
timeToIdle: number of milliseconds of inactivity which makes activity detector transition to 'idle' (
activityEvents: the user events which make activity detector transition from 'idle' to 'active'. The default list of activityEvents is
['click', 'mousemove', 'keydown', 'DOMMouseScroll', 'mousewheel', 'mousedown', 'touchstart', 'touchmove', 'focus']
inactivityEvents: the list of events which make the activity detector transition from 'active' to 'idle' without waiting for
timeToIdletimeout. By default:
ignoredEventsWhenIdle: list of events to ignore in idle state. By default:
initialState: can be
Visit: https://react-corekit.github.io/use-idle/ for a minimalistic live demo (Including mousemove event).
MIT © glongh