useSize
A hook that observes size change of an element.
Overview
A hook that observes size change of an element.
Installation
Open inpnpm dlx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useSize.jsonnpx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useSize.jsonyarn shadcn@latest add https://shadcn-ahooks.vercel.app/r/useSize.jsonbun shadcn@latest add https://shadcn-ahooks.vercel.app/r/useSize.jsonA hook that observes size change of an element.
Examples
Default usage
Pass in the DOM element
API
const size = useSize(target);Params
| Property | Description | Type | Default |
|---|---|---|---|
| target | DOM element or ref object | Element | (() => Element) | MutableRefObject<Element> | - |
Result
| Property | Description | Type | Default |
| -- | - | | - |
| size | Size of the element | { width: number, height: number } \| undefined | { width: target.clientWidth, height: target.clientHeight } \| undefined |