import React from 'react' ; import { getWindow , isBrowser } from '../../helpers/window' ; export type WindowEventProps < T extends keyof WindowEventMap > = { /**
     * Type of event
     */ event ? : T ; /**
     * Event callback function
     */ handler : ( e : WindowEventMap [ T ] ) => void ; } ; example function WindowEvent < T extends keyof WindowEventMap > ( props ) { const { event , handler } = props ; if ( ! isBrowser ( ) ) { return null ; } const environment = getWindow ( ) ; function addEvent ( ) { environment . addEventListener ( event , handler ) ; } function removeEvent ( ) { environment . removeEventListener ( event , handler ) ; } React . useEffect ( ( ) => { addEvent ( ) ; return ( ) => { removeEvent ( ) ; } ; } , [ event , handler ] ) ; return null ; } WindowEvent . displayName = 'WindowEvent' ; export default WindowEvent ;