import { useEffect } from 'react' ; function useOutsideClick ( ref , callback ) { useEffect ( ( ) => { function handleClickOutside ( event ) { if ( ref . current && ! ref . current . contains ( event . target as Node ) ) { typeof callback === 'function' && callback ( ) ; } } document . addEventListener ( 'mousedown' , handleClickOutside ) ; return ( ) => { document . removeEventListener ( 'mousedown' , handleClickOutside ) ; } ; } , [ ref , callback ] ) ; } export default useOutsideClick ;