UNPKG

@brightsoftware/date-np

Version:

Simple & minimal Nepali date picker that just works.

23 lines (22 loc) 681 B
import { useEffect as i } from "react"; const s = ({ ref: n, callback: c, active: o }) => { i(() => { let r; if (!o) return; const t = (e) => { e.stopImmediatePropagation(), e.stopPropagation(), n.current && !n.current.contains(e.target) && (c(e), document.removeEventListener("click", t), document.removeEventListener("touchstart", t)); }; return r = setTimeout(() => { document.addEventListener("click", t), document.addEventListener("touchstart", t); }, 0), () => { clearTimeout(r), document.removeEventListener("click", t), document.removeEventListener("touchstart", t); }; }, [o]); }; export { s as useOutsideClick };