source: imaps-frontend/node_modules/react-use/lib/useMeasureDirty.js@ d565449

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

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.1 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var tslib_1 = require("tslib");
4var react_1 = require("react");
5var resize_observer_polyfill_1 = tslib_1.__importDefault(require("resize-observer-polyfill"));
6var useMeasureDirty = function (ref) {
7 var frame = react_1.useRef(0);
8 var _a = react_1.useState({
9 width: 0,
10 height: 0,
11 top: 0,
12 left: 0,
13 bottom: 0,
14 right: 0,
15 }), rect = _a[0], set = _a[1];
16 var observer = react_1.useState(function () {
17 return new resize_observer_polyfill_1.default(function (entries) {
18 var entry = entries[0];
19 if (entry) {
20 cancelAnimationFrame(frame.current);
21 frame.current = requestAnimationFrame(function () {
22 if (ref.current) {
23 set(entry.contentRect);
24 }
25 });
26 }
27 });
28 })[0];
29 react_1.useEffect(function () {
30 observer.disconnect();
31 if (ref.current) {
32 observer.observe(ref.current);
33 }
34 }, [ref]);
35 return rect;
36};
37exports.default = useMeasureDirty;
Note: See TracBrowser for help on using the repository browser.