useElementSize

Tags:

A React Hook that returns the size of an element.

Demo

Try to resize the textarea to see the size changes.

Source

Usage

See API for more details.

Source

Click links below to view source on GitHub.

API

const { width, height, ...useResizeObserverReturns } = useElementSize(elementTarget, defaultValue, options)

ElementTarget

ElementTarget is a union type that represents various kinds of elements that can be targeted.

See ElementTarget or ElementTarget Types for more details.

DefaultValue

export type ElementSize = { /** * The width of the element. */ width: number /** * The height of the element. */ height: number }

Options

Options of useResizeObserver, see useResizeObserver#options for more details.

Returns

Returns of useResizeObserver, see useResizeObserver#returns for more details.

export type UseElementSizeReturns = ElementSize & UseResizeObserverReturns