@supunlakmal/hooks
Version:
A collection of reusable React hooks
22 lines (21 loc) • 869 B
TypeScript
import { type RefObject } from 'react';
export type Measures = {
width: number;
height: number;
};
/**
* Uses ResizeObserver to track element dimensions and re-render component when they change.
* Provides a ref to attach to the target element.
* Assumes useResizeObserver returns a SINGLE entry object or null.
*
* @template T The type of the DOM element being measured.
* @param enabled Whether resize observation and state updates are enabled. Defaults to true.
* @returns A tuple containing:
* - `measures`: An object with `width` and `height`, or `undefined` if there is no measures.
* - `ref`: A RefObject to attach to the DOM element being measured.
*/
export declare const useMeasure: <T extends Element>(enabled?: boolean) => {
measures: Measures | undefined;
ref: RefObject<T | null>;
};
export default useMeasure;