import type { MutableRefObject } from "react"; /** * useOutsideClick hook * Checks if a click happened outside a Ref. Handy for dropdowns, modals and popups etc. * * @param ref Ref whose outside click needs to be listened to * @param handler Callback to fire on outside click * @param when A boolean which which activates the hook only when it is true. Useful for conditionally enable the outside click * @see https://rooks.vercel.app/docs/hooks/useOutsideClick * @example * ```tsx * import { useOutsideClick } from "../hooks/useOutsideClick"; * import { useRef } from "react"; * import { noop } from "../utils/noop"; * * const MyComponent = () => { * const ref = useRef(null); * const [isOpen, setIsOpen] = useState(false); * const handleOutsideClick = () => setIsOpen(false); * useOutsideClick(ref, handleOutsideClick); * return ( *
* * {isOpen && ( *
Inside
* )} *
* ); * } * ``` */ declare function useOutsideClick(ref: MutableRefObject, handler: (event: MouseEvent | TouchEvent) => void, when?: boolean): void; export { useOutsideClick };