(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "tslib", "react"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    exports.useResizeObserver = void 0;
    var tslib_1 = require("tslib");
    var react_1 = require("react");
    var useResizeObserver = function (ref, callback) {
        var _a = (0, tslib_1.__read)((0, react_1.useState)(), 2), width = _a[0], setWidth = _a[1];
        var _b = (0, tslib_1.__read)((0, react_1.useState)(), 2), height = _b[0], setHeight = _b[1];
        var handleResize = (0, react_1.useCallback)(function (entries) {
            if (!Array.isArray(entries)) {
                return;
            }
            var entry = entries[0];
            setWidth(entry.contentRect.width);
            setHeight(entry.contentRect.height);
            if (callback) {
                callback(entry.contentRect);
            }
        }, [callback]);
        (0, react_1.useLayoutEffect)(function () {
            if (!ref.current) {
                return;
            }
            var RO = new ResizeObserver(function (entries) {
                return handleResize(entries);
            });
            RO.observe(ref.current);
            return function () {
                RO && RO.disconnect();
                RO = null;
            };
        }, [ref]);
        return [width, height];
    };
    exports.useResizeObserver = useResizeObserver;
});
