Composables
useElementSize
An element's rendered width and height, kept up to date with a ResizeObserver. The charts use it to draw in real pixels.
0 × 0
Drag the bottom-right corner in either direction, or resize the window.
| Argument | Type | |
|---|---|---|
target | Ref<HTMLElement | undefined> | The element to watch. A template ref |
| Returned | Type | |
|---|---|---|
width | Ref<number> | Client width in px |
height | Ref<number> | Client height in px |
Notes
The size is seeded from layout before the observer first fires, so the first frame draws at the real width rather than at zero — and where ResizeObserver is missing, that seed is the measurement.
One observer is kept per element, disconnected when the target changes or the component unmounts.