@react-hookz/web
Version:
React hooks done right, for browser and SSR.
11 lines (10 loc) • 555 B
TypeScript
import { RefObject } from 'react';
/**
* Subscribes an event listener to the target, and automatically unsubscribes
* it on unmount.
*
* @param target Element ref object or element itself.
* @param params Parameters specific for target's `addEventListener`. Commonly,
* it is `[eventName, listener, options]`.
*/
export declare function useEventListener<T extends EventTarget>(target: RefObject<T> | T | null, ...params: Parameters<T['addEventListener']> | [string, EventListenerOrEventListenerObject | ((...args: any[]) => any), ...any]): void;