VisorVisor
Hooks

useClickOutside

Fires a callback when a click or touch event occurs outside the referenced element.

Usage

const ref = useRef<HTMLDivElement>(null)
useClickOutside(ref, () => setOpen(false))

Installation

npx visor add use-click-outside

Parameters

NameTypeRequiredDefaultDescription
refRefObject<T extends HTMLElement>Yes--Ref to the element that defines the "inside" boundary.
handler(event: MouseEvent | TouchEvent) => voidYes--Callback invoked when a click/touch lands outside the ref element.

Returns

This hook does not return a value.