"use client";
import { useEffect } from "react";
import { useEventCallback } from "../../utils/hooks/useEventCallback.js";
/* https://github.com/streamich/react-use/blob/master/src/useEvent.ts */
const useEventListener = (name, handler, target = typeof window !== "undefined" ? window : null) => {
    /* Keep listener identity stable so inline handlers do not re-register every render. */
    const stableHandler = useEventCallback(handler);
    useEffect(() => {
        if (!target) {
            return;
        }
        target === null || target === void 0 ? void 0 : target.addEventListener(name, stableHandler);
        return () => {
            target === null || target === void 0 ? void 0 : target.removeEventListener(name, stableHandler);
        };
    }, [name, stableHandler, target]);
};
export { useEventListener };
//# sourceMappingURL=useEventListener.js.map