Detects clicks outside of a specified element.
The HTML element type.
The callback to execute when an outside click occurs.
A ref object to attach to the target element.
This hook returns a ref to attach to the element you want to monitor. It subscribes to global pointer down events and checks if the click target is outside the ref element.
const ref = useOutsideClick(() => { closeModal();});return <div ref={ref}>Modal Content</div>; Copy
const ref = useOutsideClick(() => { closeModal();});return <div ref={ref}>Modal Content</div>;
Detects clicks outside of a specified element.