"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useListener = void 0;
var react_1 = require("react");
function useListener() {
    var id = react_1.useRef(0);
    var events = react_1.useRef(new Map());
    function addEventListener(fn) {
        id.current += 1;
        var currentId = id.current;
        events.current.set(currentId, fn);
        return function () {
            events.current.delete(currentId);
        };
    }
    react_1.useEffect(function () {
        return function () {
            events.current.clear();
        };
    }, []);
    function setValue(v) {
        Array.from(events.current.values()).forEach(function (fn) { return fn(v); });
    }
    return [addEventListener, setValue];
}
exports.useListener = useListener;
//# sourceMappingURL=useListeneter.js.map