R
fn

useClickOutside

v0.0.14testeddemo

Invokes `handler` when a pointer event occurs outside `target`. SSR-safe: no-op on the server. Handles portaled/ignored subtrees and guards against synthetic "outside" clicks on removed nodes.

Demo

Loading demo…

Signature

ts
export function useClickOutside(
  target: MaybeComputedElementRef,
  handler: (event: PointerEvent | MouseEvent) => void,
  options: UseClickOutsideOptions ={ ... }

Parameters

ParameterTypeDescription
targetMaybeComputedElementRefElement to watch. Events inside it are ignored.
handler(event: PointerEvent | MouseEvent) => voidCallback invoked with the outside event
options?UseClickOutsideOptionsOptions

Returns

VoidFunctionStop handle to remove the listeners