UNPKG

opt-table

Version:

A Responsive and Customizable Rich Table

20 lines 686 B
import { useEffect } from "react"; export function useOutsideAlerter(ref, onClick) { useEffect(() => { /** * Alert if clicked on outside of element */ function handleClickOutside(event) { if (ref.current && !ref.current.contains(event.target)) { onClick(); } } // Bind the event listener document.addEventListener("mousedown", handleClickOutside); return () => { // Unbind the event listener on clean up document.removeEventListener("mousedown", handleClickOutside); }; }, [ref]); } //# sourceMappingURL=click_away.js.map