useElementSize
A hook to track an element's width and height
Loading...
Installation
npx shadcn@latest add @shadcnhooks/use-element-sizeAPI
export interface ElementSize {
width: number
height: number
}
export interface UseElementSizeOptions {
/**
* ResizeObserver box model to use for measuring.
*
* @default 'content-box'
*/
box?: ResizeObserverBoxOptions
}
/**
* A hook to track an element's width and height.
*
* @param target - The target element to observe
* @param initialSize - Initial width and height
* @param options - Measurement options
* @returns Current element size
*/
export function useElementSize(
target: BasicTarget<Element>,
initialSize?: ElementSize,
options?: UseElementSizeOptions,
): ElementSizeCredits
Last updated on