14 lines
343 B
TypeScript
14 lines
343 B
TypeScript
import { useEffect, useState } from "react";
|
|
|
|
export function useInitialDimensions(ref: React.RefObject<HTMLElement>) {
|
|
const [dimensions, setDimensions] = useState<DOMRectReadOnly | null>(null);
|
|
|
|
useEffect(() => {
|
|
if (ref.current) {
|
|
setDimensions(ref.current.getBoundingClientRect());
|
|
}
|
|
}, [ref]);
|
|
|
|
return dimensions;
|
|
}
|