"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useResizeEffect = void 0;
var react_1 = require("react");
exports.useResizeEffect = function (elRef, fn) {
    var effectFn = react_1.useRef();
    effectFn.current = fn;
    react_1.useLayoutEffect(function () {
        if (!window.ResizeObserver)
            return undefined;
        if (elRef.current) {
            var observer_1 = new window.ResizeObserver(function () {
                var args = [];
                for (var _i = 0; _i < arguments.length; _i++) {
                    args[_i] = arguments[_i];
                }
                return effectFn.current.apply(effectFn, args);
            } //TODO not sure why args have to be passed in explicitly
            );
            var el_1 = elRef.current;
            observer_1.observe(el_1);
            return function () { return observer_1.unobserve(el_1); };
        }
        return undefined;
    }, [elRef]);
};
