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-click-outside

useClickOutside

zyeon/use-click-outside
FreeHook

A hook that runs a handler when a pointer interaction lands outside one or more referenced elements.

Install it

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

Source

src/registry/hooks/use-click-outside.tsxui.zyeon.ai/r/use-click-outside.json
1"use client"
2
3import * as React from "react"
4
5/** Document events that can be listened for. `pointerdown` alone covers mouse, touch and pen. */
6export type ClickOutsideEvent = "pointerdown" | "mousedown" | "click" | "touchstart"
7
8/** Any element ref — `useRef<HTMLDivElement>(null)` can be handed straight in. */
9export type ClickOutsideRef = React.RefObject<Element | null>
10
11export interface UseClickOutsideOptions {
12 /** Unbinds the listener (no point sitting on document while the layer is closed). Defaults to true. */
13 enabled?: boolean
14 /** Which document events to listen for. Defaults to ["pointerdown"]. */
15 events?: ClickOutsideEvent[]
16}
17
18/** Module-level constant: the default reuses one array identity, saving a pointless dependency change. */
19const DEFAULT_EVENTS: ClickOutsideEvent[] = ["pointerdown"]
20
21/**
22 * Calls `handler` when an interaction lands outside **all** of the given refs. An array is
23 * accepted for the classic case of a trigger and a layer being two DOM nodes with no nesting
24 * between them (dropdowns, portalled popovers): a press on the trigger must not count as
25 * outside, or the button is closed and then reopened and the layer never appears to open.
26 *
27 * - **SSR safe**: `document` is only touched inside the effect, never during render.
28 * - **No listener churn**: `handler` and `refs` live in refs refreshed each render, and
29 * `events` is serialised into a string dependency — inline arrows and inline arrays are
30 * what consumers actually write, and passing those straight into the dependency array
31 * would rebind the document listener on every render.
32 * - **Detached nodes**: see the `isConnected` comment in `listener`; that is the trap this
33 * hook exists to avoid.
34 * - `pointerdown` rather than `click` by default: dismissal happens the moment you press,
35 * which feels more direct and sidesteps the drag that starts inside the layer and
36 * releases outside it.
37 */
38export function useClickOutside(
39 refs: ClickOutsideRef | ClickOutsideRef[],
40 handler: (event: Event) => void,
41 options: UseClickOutsideOptions = {},
42): void {
43 const { enabled = true, events = DEFAULT_EVENTS } = options
44
45 const handlerRef = React.useRef(handler)
46 const refsRef = React.useRef(refs)
47 React.useEffect(() => {
48 handlerRef.current = handler
49 refsRef.current = refs
50 })
51
52 // `events` is usually an array literal written at the call site, so by reference it counts
53// … truncated

Files it writes

  • src/registry/hooks/use-click-outside.tsx

Facts

Registry
zyeon
Type
registry:hook
Access
Free
Files written
1
Licence
MIT
In the index
at or before 2026-08-13
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
useClipboardPasteuse-clipboard-pastezyeonHooksFreeno deps
useControllableStateuse-controllable-statezyeonHooksFreeno deps
useCookieuse-cookiezyeonHooksFreeno deps
useCopyToClipboarduse-copy-to-clipboardzyeonHooksFreeno deps
useCountdownuse-countdownzyeonHooksFreeno 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