useClickOutside

Tags:

A React Hook that allows you to detect clicks outside of a specified element.

Demo

Source

Usage

See API for more details.

Source

Click links below to view source on GitHub.

API

useClickOutside(elementTarget, callback, options)

ElementTarget

ElementTarget is a union type that represents various kinds of elements that can be targeted.

See ElementTarget or ElementTarget Types for more details.

Callback

export type UseClickOutsideHandler = (evt: MouseEvent | PointerEvent) => void

Options

export type UseClickOutsideOptions = { /** * List of elements that should not trigger the event. */ ignore?: ElementTarget[] }