MCPcopy Create free account
hub / github.com/benjitaylor/agentation / useMeasure

Function useMeasure

package/example/src/hooks/useMeasure.ts:9–35  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

7
8/** Measures the width/height of an element using ResizeObserver. */
9export const useMeasure = <T extends HTMLElement>(): [
10 React.RefObject<T>,
11 Bounds,
12] => {
13 const ref = React.useRef<T>(null);
14 const [bounds, setBounds] = React.useState<Bounds>({
15 width: undefined,
16 height: undefined,
17 });
18
19 React.useLayoutEffect(() => {
20 if (!ref.current) return;
21
22 const observer = new ResizeObserver((entries) => {
23 const entry = entries[0];
24 setBounds({
25 width: entry.contentRect.width,
26 height: entry.contentRect.height,
27 });
28 });
29 observer.observe(ref.current);
30
31 return () => observer.disconnect();
32 }, []);
33
34 return [ref, bounds];
35};

Callers 1

HeightFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…