import React, { useEffect } from "react"; const useOutsideClickDetector = (ref: React.RefObject, callback: () => void) => { const handleClick = (event: MouseEvent) => { if (ref.current && !ref.current.contains(event.target as Node)) { callback(); } }; useEffect(() => { document.addEventListener("click", handleClick); return () => { document.removeEventListener("click", handleClick); }; }); }; export default useOutsideClickDetector;