import { MutableRefObject , useEffect } from 'react' ; const useClickOutside = ( ref , handler ) => { useEffect ( ( ) => { const callback = ( event ) => { const el = ref . current ; if ( ! event || ! el || el . contains ( ( event as any ) . target ) ) return ; handler ( event ) ; } ; document . addEventListener ( 'click' , callback ) ; return ( ) => document . removeEventListener ( 'click' , callback ) ; } , [ ref , handler ] ) ; } ; export default useClickOutside ;