source: imaps-frontend/node_modules/react-use/lib/useMeasure.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.4 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var tslib_1 = require("tslib");
4var react_1 = require("react");
5var useIsomorphicLayoutEffect_1 = tslib_1.__importDefault(require("./useIsomorphicLayoutEffect"));
6var util_1 = require("./misc/util");
7var defaultState = {
8 x: 0,
9 y: 0,
10 width: 0,
11 height: 0,
12 top: 0,
13 left: 0,
14 bottom: 0,
15 right: 0,
16};
17function useMeasure() {
18 var _a = react_1.useState(null), element = _a[0], ref = _a[1];
19 var _b = react_1.useState(defaultState), rect = _b[0], setRect = _b[1];
20 var observer = react_1.useMemo(function () {
21 return new window.ResizeObserver(function (entries) {
22 if (entries[0]) {
23 var _a = entries[0].contentRect, x = _a.x, y = _a.y, width = _a.width, height = _a.height, top_1 = _a.top, left = _a.left, bottom = _a.bottom, right = _a.right;
24 setRect({ x: x, y: y, width: width, height: height, top: top_1, left: left, bottom: bottom, right: right });
25 }
26 });
27 }, []);
28 useIsomorphicLayoutEffect_1.default(function () {
29 if (!element)
30 return;
31 observer.observe(element);
32 return function () {
33 observer.disconnect();
34 };
35 }, [element]);
36 return [ref, rect];
37}
38exports.default = util_1.isBrowser && typeof window.ResizeObserver !== 'undefined'
39 ? useMeasure
40 : (function () { return [util_1.noop, defaultState]; });
Note: See TracBrowser for help on using the repository browser.