React hook to retrieve the size of an element
npm i use-size-performant
// or
yarn add use-size-performant
import useSize from "use-size-performant";
const YourComponent = () => {
const ref = useRef(null);
const { height, width } = useSize(ref);
return (
<div ref={ref}>
<p>Height: {height}</p>
<p>Width: {width}</p>
</div>
);
};
import useSize from "use-size-performant";
const YourComponent = () => {
const dom = document.querySelector('body');
const { height, width } = useSize(dom);
return (
<div>
<p>Height: {height}</p>
<p>Width: {width}</p>
</div>
);
};
MIT © Akshit Kr Nagpal