"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useComponentSize = void 0;
var react_1 = require("react");
function getSize(el) {
    if (!el) {
        return {
            width: 0,
            height: 0,
        };
    }
    return {
        width: el.offsetWidth,
        height: el.offsetHeight,
    };
}
function useComponentSize(ref) {
    var _a = react_1.useState(getSize(ref ? ref.current : {})), size = _a[0], setSize = _a[1];
    var handleResize = react_1.useCallback(function handleResize() {
        if (ref.current) {
            setSize(getSize(ref.current));
        }
    }, [ref]);
    react_1.useEffect(function () {
        if (!ref.current) {
            return;
        }
        handleResize();
        window.addEventListener('resize', handleResize);
        return function () {
            window.removeEventListener('resize', handleResize);
        };
    }, [ref]);
    return size;
}
exports.useComponentSize = useComponentSize;
//# sourceMappingURL=useComponentSize.js.map