useSize

A hook to subscribe DOM element size change.

The API is different from ahooks.

Examples

Basic usage

API

const size = useSize(target);

Params

PropertyDescriptionTypeDefault
targetDOM element or Ref ObjectHTMLElement | (() => HTMLElement) | MutableRefObject-
optionsObject-

Options

参数类型默认值说明
onChangeFunctionundefinedsize change callback

Result

PropertyDescriptionType
sizesize of the DOM{ width: number, height: number }

最近更新: