UNPKG

@wojtekmaj/react-hooks

Version:

A collection of React Hooks.

14 lines (13 loc) 878 B
type GlobalAndWindowEventHandlersEventMap = WindowEventHandlersEventMap & GlobalEventHandlersEventMap; /** * Adds event listener to a given element. * * @param {Element | Window | Document} [element] Element to attach the listener to * @param {string} type Event type * @param {EventListenerOrEventListenerObject} listener Event listener * @returns {void} */ export default function useEventListener(element: Element | null, type: string, listener: EventListenerOrEventListenerObject): void; export default function useEventListener<U extends keyof GlobalAndWindowEventHandlersEventMap>(element: Window | null, type: U, listener: (event: GlobalAndWindowEventHandlersEventMap[U]) => void): void; export default function useEventListener<U extends keyof DocumentEventMap>(element: Document | null, type: U, listener: (event: DocumentEventMap[U]) => void): void; export {};