GoScrobble/web/node_modules/@restart/hooks/cjs/useResizeObserver.d.ts

26 lines
606 B
TypeScript
Raw Permalink Normal View History

2022-04-25 02:47:15 +00:00
export interface Rect {
width: number;
height: number;
x?: number;
y?: number;
}
/**
* Efficiently observe size changes on an element. Depends on the `ResizeObserver` api,
* and polyfills are needed in older browsers.
*
* ```ts
* const [ref, attachRef] = useCallbackRef(null);
*
* const rect = useResizeObserver(ref);
*
* return (
* <div ref={attachRef}>
* {JSON.stringify(rect)}
* </div>
* )
* ```
*
* @param element The DOM element to observe
*/
export default function useResizeObserver<TElement extends Element>(element: TElement | null | undefined): Rect | null;