import * as React from "react" ; param callback example export const useClickOutside = < T extends HTMLElement > ( callback ) => { const trigger = React . useRef < T > ( null ) ; React . useEffect ( ( ) => { const doc = ( trigger . current && trigger . current . ownerDocument ) || document ; /** The event handler determining if the user clicked outside. */ const onDocumentClick = ( e ) => { if ( trigger . current && trigger . current . contains ( e . target as Node ) ) { callback ( false ) ; e . stopPropagation ( ) ; } else { callback ( true ) ; } } ; doc . addEventListener ( "mouseup" , onDocumentClick ) ; doc . addEventListener ( "touchend" , onDocumentClick ) ; return ( ) => { doc . removeEventListener ( "mouseup" , onDocumentClick ) ; doc . removeEventListener ( "touchend" , onDocumentClick ) ; } ; } , [ callback ] ) ; return trigger ; } ;