BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/zyeon/use-idle

useIdle

zyeon/use-idle
FreeHook

Flips a boolean idle state after a period with no pointer, keyboard, wheel, or touch activity, with a throttled reset and SSR-safe cleanup.

Install it

npx shadcn@latest add https://ui.zyeon.ai/r/use-idle.json

Source

src/registry/hooks/use-idle.tsxui.zyeon.ai/r/use-idle.json
1"use client"
2
3import * as React from "react"
4
5export interface UseIdleOptions {
6 /** Activity events to listen for, attached to `window` as passive. Passing this replaces the default list wholesale. */
7 events?: string[]
8 /** Initial idle value at mount. Default `false` — treated as "activity just happened". */
9 initialState?: boolean
10}
11
12const DEFAULT_EVENTS = ["pointermove", "pointerdown", "keydown", "wheel", "touchstart"]
13
14// high-frequency events (pointermove/wheel) reach handleActivity on every tick; a
15// clearTimeout + setTimeout per tick costs real time with many listeners or on a weak
16// device. Throttle by timestamp comparison instead: activity inside the window is
17// dropped and only the first activity past it resets the timer. The cost is that idle
18// can fire up to one window early, which is fine for idle detection.
19// the window has to narrow with timeout: a fixed 1s would call continuous activity idle
20// whenever timeout < 1s (the 500ms timer expires first, while the next activity let
21// through has to wait for 1s).
22const throttleFor = (timeout: number) => Math.min(1000, Math.max(100, Math.floor(timeout / 3)))
23
24/**
25 * User idle detection. Mounting starts a `timeout` ms timer; any of `events` (pointer
26 * move/down, keyboard, wheel, touch by default) counts as activity — it sets `idle`
27 * to `false` and restarts the timer, and the timer expiring sets it to `true`.
28 *
29 * `visibilitychange` is handled separately and cannot be switched off through
30 * `events`: coming back to the tab (`document.visibilityState === "visible"`) counts
31 * as activity and resets the timer, but leaving it (hidden) does **not** force idle —
32 * the timer keeps counting real elapsed time and flips on its own, with no "away means
33 * idle" special case (a background tab's timer may be throttled and fire late; that
34 * drift is accepted rather than chased second by second).
35 *
36 * Every `setState` happens in an event or timer callback, never during render or
37 * synchronously in an effect body, so it is SSR-safe; unmount clears the timer and
38 * every listener.
39 */
40export function useIdle(timeout = 60000, options: UseIdleOptions = {}): boolean {
41 const { events = DEFAULT_EVENTS, initialState = false } = options
42 const [idle, setIdle] = React.useState(initialState)
43
44 // latest events in a ref; the effect depends on eventsKey below (contents, not the
45 // array identity), so an inline array literal from a consumer does not tear the
46// … truncated

Files it writes

  • src/registry/hooks/use-idle.tsx

Facts

Registry
zyeon
Type
registry:hook
Access
Free
Files written
1
Licence
MIT
In the index
at or before 2026-08-09
Last confirmed
today

Go to the source

ui.zyeon.ai Zyeon-AI/zyeon-ui-components on GitHub Raw registry item This item as JSON

More from zyeon

All 893 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
useAsyncuse-asynczyeonHooksFreeno deps
useBatteryuse-batteryzyeonHooksFreeno deps
useBroadcastChanneluse-broadcast-channelzyeonHooksFreeno deps
useClickOutsideuse-click-outsidezyeonHooksFreeno deps
useClipboardPasteuse-clipboard-pastezyeonHooksFreeno deps
useControllableStateuse-controllable-statezyeonHooksFreeno deps
useCookieuse-cookiezyeonHooksFreeno deps
useCopyToClipboarduse-copy-to-clipboardzyeonHooksFreeno deps

Also from Kynth Studios

Built for the same person as BlockDex

SkillWorks

Claude Code skills and plugins, scored

skillworks.kynth.studio

RuleStack

AGENTS.md gallery and agent-config comparison

rulestack.kynth.studio

ToolDrift

What the AI coding tools changed last night

tooldrift.kynth.studio

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and ToolDrift

part of Toolproof, the measurement layer for AI agent tooling

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and ToolDrift

part of Toolproof, the measurement layer for AI agent tooling

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and ToolDrift

part of Toolproof, the measurement layer for AI agent tooling

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex