Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | 19x 50x 50x 48x 48x | import { useEffect } from "react";
interface IUseEventListener {
target: Element | HTMLElement | Document | Window | null;
type: string;
listener: EventListenerOrEventListenerObject;
options?: boolean | AddEventListenerOptions;
ignore?: boolean;
}
export function useEventListener({
target,
type,
listener,
options,
ignore,
}: IUseEventListener): void {
useEffect(() => {
if (!target || ignore) {
return;
}
target.addEventListener(type, listener, options);
return () => {
target.removeEventListener(type, listener, options);
};
}, [target, type, listener, options, ignore]);
}
|