useOutsideClick
useOutsideClick
is a custom hook that handles a click outside a specified DOM element, like a div
.
Import#
import { useOutsideClick } from "@chakra-ui/react"
Return value#
The useOutsideClick
hook receives a reference to a DOM element and a handler when a clicks happens
outside this given element.
Name | Type | Default | Description |
---|---|---|---|
ref | object | The ref to access the DOM. | |
handler | function | Callback function to handle the click. |
This hooks is compatible with mouse and touch events.
Usage#
Editable Example