1 import { useLayoutEffect, useState } from 'react';
3 import type { Rect } from './observeRect';
4 import observeRect from './observeRect';
6 export function useRect(nodeRef: HTMLElement | null, observe = true, once = false, dependency?: any) {
7 const [rect, setRect] = useState<Rect | undefined>(undefined);
9 useLayoutEffect(() => {
10 if (!nodeRef || !observe) {
16 let onceState = false;
18 const stop = observeRect(nodeRef, (rect: Rect) => {
29 return observeRect(nodeRef, (rect) => {
32 }, [nodeRef, observe, once, dependency]);