UNPKG

@jbrowse/core

Version:

JBrowse 2 core libraries used by plugins

34 lines (33 loc) 952 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = useMeasure; const react_1 = require("react"); function useMeasure() { const ref = (0, react_1.useRef)(null); const [dims, setDims] = (0, react_1.useState)({ width: undefined, height: undefined, }); (0, react_1.useEffect)(() => { if (!ref.current) { return; } const RS = typeof window !== 'undefined' && 'ResizeObserver' in window ? window.ResizeObserver : undefined; if (!RS) { return; } const observer = new RS(entries => { setDims({ width: entries[0].contentRect.width, height: entries[0].contentRect.height, }); }); observer.observe(ref.current); return () => { observer.disconnect(); }; }, []); return [ref, dims]; }