Skip to content

Latest commit

 

History

History
51 lines (40 loc) · 929 Bytes

README.md

File metadata and controls

51 lines (40 loc) · 929 Bytes

use-size-performant

React hook to retrieve the size of an element

NPM

Installation

npm i use-size-performant
// or
yarn add use-size-performant

Usage

Using Ref

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>
  );
};

Using DOM elements

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>
  );
};

License

MIT © Akshit Kr Nagpal