Description:
use-element-size is a React hook for tracking the size of React-dom element in the React app.
Install & Import:
# NPM $ npm i use-element-size --save
import React from 'react'
import { useElementSize } from 'use-element-size'Basic usage:
onst Example = () => {
const ref = useElementSize((size, prevSize, elem) => {
console.log({ size, prevSize, elem })
})
return (
<div
ref={ref}
style={{
position: 'relative',
width: '50%',
height: '50%',
}}
/>
)
}