useSize
Measures real-time element pixel dimensions with ResizeObserver.
1.2 KB
•Updated on September 3, 2026
Installation
Bash
pnpm dlx shadcn@latest add @spaceui/hooks-dom-use-sizeUsage
Code
import { useSize } from '@/hooks/use-size'
const ref = React.useRef(null)
const { width, height } = useSize(ref)API Reference
Parameters / Props
| Parameter | Type | Default | Description |
|---|---|---|---|
targetRef | RefObject<HTMLElement> | required | Ref to measure. |
Return Value
| Property | Type | Description |
|---|---|---|
width | number | Width in pixels. |
height | number | Height in pixels. |