useEventListener

Safely applies events when the component mounts and cleans it up when it gets unmounted. Also allows you to supply a function to apply the events to a Element, Window or Document.

Usage

useEventListener<"scroll">(event: "scroll", listener: Arrayable<(this: Window, ev: Event) => any>, options?: AddEventListenerOptions & {
    ref?: (() => EventTarget | null) | null;
}): void
useEventListener
(
"scroll", (e: Evente) => { // code goes here }, { ref?: (() => EventTarget | null) | null | undefinedref: () => var document: Document
[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/document)
document
,
} )