import type { RefObject } from 'react' ; import { useEffect } from 'react' ; /**
 * Hook that alerts clicks outside of the passed ref
 */ const useClickOutside = ( ref , handler ) => { useEffect ( ( ) => { /**
         * Alert if clicked on outside of element
         */ const handleClickOutside = ( event ) => { if ( ref . current && ! ref . current . contains ( event . target ) ) { if ( typeof handler === 'function' ) { handler ( ) ; } } } ; document . addEventListener ( 'mouseup' , handleClickOutside ) ; return ( ) => { document . removeEventListener ( 'mouseup' , handleClickOutside ) ; } ; } , [ ref , handler ] ) ; } ; export default useClickOutside ;