Attach an event listener to an element and remove it when the component unmounts.
This is custom React hooks, you need to follow the Basic Rules when you use it.
Count the clicks of an element without writing the effect.
const useEventListener = <
K extends keyof HTMLElementEventMap,
T extends HTMLElement = HTMLElement,
>(
type: K,
listener: (event: HTMLElementEventMap[K]) => void,
options?: boolean | AddEventListenerOptions,
) => RefObject<T | null>