Develop ultra fast with Prismane 🎉

useIdle

useIdle hook provides a simple way to handle when a client is active and idle.

Import

import { useIdle } from "@prismane/core/hooks";

Usage

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

  return (
    <Text
      cl={(theme) => (theme.mode === "dark" ? ["base", 200] : ["base", 700])}
    >
      Idle: {isIdle.toString()}
    </Text>
  );
}

API

Parameters

NameTypeDescriptionDefault
timeoutnumberThe timeout from the last user event, after which, the state will become idle.3000
eventsstring[]The set of events which will count as a user action and remove the idle state.mousemove, keyup, click, scroll
initialbooleanThe initial idle state of the user.false

Return Value

NameTypeDescription
isIdlebooleanThe state of the user.