generated at
use-event-listener
任意のDOM要素に対してElement.addEventListener()を実行するCustom Hook

script.js
import {useEffect} from '../preact@10.5.13/hooks.js'; export function useEventListener(element, type, listener, options) { useEffect(() => { element.addEventListener(type, listener, options); return () => element.removeEventListener(type, listener, options); }, [element, listener, options, type]); }