UNPKG

606 BTypeScriptView Raw
1export interface Rect {
2 width: number;
3 height: number;
4 x?: number;
5 y?: number;
6}
7/**
8 * Efficiently observe size changes on an element. Depends on the `ResizeObserver` api,
9 * and polyfills are needed in older browsers.
10 *
11 * ```ts
12 * const [ref, attachRef] = useCallbackRef(null);
13 *
14 * const rect = useResizeObserver(ref);
15 *
16 * return (
17 * <div ref={attachRef}>
18 * {JSON.stringify(rect)}
19 * </div>
20 * )
21 * ```
22 *
23 * @param element The DOM element to observe
24 */
25export default function useResizeObserver<TElement extends Element>(element: TElement | null | undefined): Rect | null;