UNPKG

1.07 kBTypeScriptView Raw
1import type { BasicTarget } from '../utils/domTarget';
2type noop = (...p: any) => void;
3export type Target = BasicTarget<HTMLElement | Element | Window | Document>;
4type Options<T extends Target = Target> = {
5 target?: T;
6 capture?: boolean;
7 once?: boolean;
8 passive?: boolean;
9};
10declare function useEventListener<K extends keyof HTMLElementEventMap>(eventName: K, handler: (ev: HTMLElementEventMap[K]) => void, options?: Options<HTMLElement>): void;
11declare function useEventListener<K extends keyof ElementEventMap>(eventName: K, handler: (ev: ElementEventMap[K]) => void, options?: Options<Element>): void;
12declare function useEventListener<K extends keyof DocumentEventMap>(eventName: K, handler: (ev: DocumentEventMap[K]) => void, options?: Options<Document>): void;
13declare function useEventListener<K extends keyof WindowEventMap>(eventName: K, handler: (ev: WindowEventMap[K]) => void, options?: Options<Window>): void;
14declare function useEventListener(eventName: string, handler: noop, options: Options): void;
15export default useEventListener;