import { useEffect , RefObject } from 'react' ; export const useOutsideClick = ( ref , callback , deps ? ) => { const handleClick = ( e ) => { if ( ref . current && ! ref . current . contains ( e . target as HTMLInputElement ) ) { callback ( ) ; } } ; useEffect ( ( ) => { document . addEventListener ( 'mousedown' , handleClick ) ; return ( ) => { document . removeEventListener ( 'mousedown' , handleClick ) ; } ; } , deps ) ; } ;