Skip to Content
react-utilsuseElementSize

useElementSize

See source on Github

Tracks a ref element size which updates on element resize.

  • @param ref - An element reference to measure
  • @param options - Configurable options
  • @returns An object containing size information

Example

const ref = useRef<HTMLDivElement>(null) const { clientWidth, clientHeight } = useElementSize(ref) return ( <div ref={ref}> {innerWidth ? `${innerWidth} x ${innerHeight}` : 'Loading...'} </div> )