import { useEffect } from 'react' ; export const useHtmlElementEventListener = < K extends keyof HTMLElementEventMap > ( element , type , listener , deps = [ ] ) => { useEffect ( ( ) => { if ( element ) { element . addEventListener ( type , listener as any ) ; return ( ) => element . removeEventListener ( type , listener as any ) ; } } , [ element , listener , type , ... deps ] ) ; } ;