React hook to get bounding client rect
npm install use-element-positionReact hook to get bounding client rect
``js
import { useElementPosition } from 'use-element-position'
const MyComponent = () => {
const [ref, { width }] = useElementPosition({ width: 0 })
return (
Or use the wrapper component
`js
import { WithPosition } from 'use-element-position'const MyComponent = ({ width }) => (
My width is {width}px
)const MyWrapperComponent = () => (
)
`getBoundingClientRect` :