"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = require("react");
const __1 = require("..");
const ResizeObserver_1 = __importDefault(require("../common/ResizeObserver"));
function useSize(ref, callback, dependencies = []) {
    (0, react_1.useEffect)(() => {
        if (!__1.isUXP) {
            // normal browsers calculate the correct size as soon as it's in the DOM.
            callback(ref.current);
        }
        let resizeObserver = new ResizeObserver_1.default(() => {
            callback(ref.current);
        });
        resizeObserver.observe(ref.current);
        return () => {
            resizeObserver.unobserve(ref.current);
        };
    }, [ref.current, ...dependencies]);
}
exports.default = useSize;
