useOnOutsideClick

A utility hook that calls a user-provided callback function when the user clicks outside of the provided container.

Examples

Default

Click outside of this div to hide it

Prevent callback when clicking specified elements

You can also pass an array of ignoredRefs to prevent calling the callback function on additional elements on the page. This can be handy for ignoring clicks on trigger buttons that already manage the open/closed state of content.

Click outside of this div to close the overlay

API

Loading data for useOnOutsideClick...