"use strict";
"use client";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useEventListener = void 0;
const react_1 = require("react");
const useEventCallback_1 = require("../../utils/hooks/useEventCallback");
/* 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 = (0, useEventCallback_1.useEventCallback)(handler);
    (0, react_1.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]);
};
exports.useEventListener = useEventListener;
//# sourceMappingURL=useEventListener.js.map