useOutsideClick

useOutsideClick is a custom hook that handles click events outside a specific DOM element, like a div. A handler is invoked when a click or touch event happens outside the referenced element.

This hook is compatible with mouse and touch events.

Import#

import { useOutsideClick } from "@chakra-ui/react"

Usage#

Editable Example

Parameters#

The useOutsideClick hook accepts an object with the following properties:

refrequired

Description

The reference to a DOM element.

Type
RefObject<HTMLElement>

handler

Description

Function invoked when a click is triggered outside the referenced element.

Type
((e: Event) => void)
Edit this page

Proudly made inNigeria by Segun Adebayo