Skip to content

useOutsideAlerter

A hook that calls the passed callback function when you click outside of a specified element.

source

Usage

import { useOutsideAlerter } from '@w3ux/hooks';
 
...
 
// Close a floating menu if clicked outside of its container.
useOutsideAlerter(menuContainerRef, () => {
  closeMenu();
});