Skip to main content

useIdle

React sensor hook that tracks if user on the page is idle

Usage

Live Editor

function Demo() {
  const isIdle = useIdle(3e3);

  return (
    <div>
      <div>User is idle: {isIdle ? "Yes 😴" : "Nope"}</div>
    </div>
  );
};

Result
Loading...

API

UseIdle

Returns

boolean: whether user is idle

Arguments

ArgumentDescriptionTypeDefaultValue
msdetection timenumber | undefined60e3
initialStateinitial valueboolean | undefinedfalse
eventslistener events(keyof WindowEventMap)[] | undefined["mousemove","mousedown","resize","keydown","touchstart","wheel"]