Skip to content

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.

ArgumentType
targetRef<HTMLElement | undefined>The element to watch. A template ref
ReturnedType
widthRef<number>Client width in px
heightRef<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.