source: imaps-frontend/node_modules/react-use/esm/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: 991 bytes
Line 
1import { useEffect, useRef, useState } from 'react';
2import ResizeObserver from 'resize-observer-polyfill';
3var useMeasureDirty = function (ref) {
4 var frame = useRef(0);
5 var _a = useState({
6 width: 0,
7 height: 0,
8 top: 0,
9 left: 0,
10 bottom: 0,
11 right: 0,
12 }), rect = _a[0], set = _a[1];
13 var observer = useState(function () {
14 return new ResizeObserver(function (entries) {
15 var entry = entries[0];
16 if (entry) {
17 cancelAnimationFrame(frame.current);
18 frame.current = requestAnimationFrame(function () {
19 if (ref.current) {
20 set(entry.contentRect);
21 }
22 });
23 }
24 });
25 })[0];
26 useEffect(function () {
27 observer.disconnect();
28 if (ref.current) {
29 observer.observe(ref.current);
30 }
31 }, [ref]);
32 return rect;
33};
34export default useMeasureDirty;
Note: See TracBrowser for help on using the repository browser.