import { MutableRefObject , useEffect } from 'react' ; const useClickOutside = ( ref , func ) : void => { useEffect ( ( ) => { const handleClickOutside = ( event ) => { if ( ref . current && ! ref . current . contains ( event . target as Node ) ) { func ( event ) ; } } ; window . addEventListener ( 'click' , handleClickOutside ) ; window . addEventListener ( 'auxclick' , handleClickOutside ) ; return ( ) => { window . removeEventListener ( 'click' , handleClickOutside ) ; window . removeEventListener ( 'auxclick' , handleClickOutside ) ; } ; } , [ ] ) ; } ; export default useClickOutside ;