An open API service indexing awesome lists of open source software.

https://github.com/akshitkrnagpal/use-size-performant

React hook to retrieve the size of an element
https://github.com/akshitkrnagpal/use-size-performant

react react-hooks resize-observer size

Last synced: 30 days ago
JSON representation

React hook to retrieve the size of an element

Awesome Lists containing this project

README

          

# use-size-performant

> React hook to retrieve the size of an element

[![NPM](https://img.shields.io/npm/v/use-size-performant.svg)](https://www.npmjs.com/package/use-size-performant)

## Installation

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

## Usage

### Using Ref

```js
import useSize from "use-size-performant";
const YourComponent = () => {
const ref = useRef(null);
const { height, width } = useSize(ref);
return (


Height: {height}


Width: {width}



);
};
```

### Using DOM elements

```js
import useSize from "use-size-performant";
const YourComponent = () => {
const dom = document.querySelector('body');
const { height, width } = useSize(dom);
return (


Height: {height}


Width: {width}



);
};
```

## License

MIT © [Akshit Kr Nagpal](https://github.com/akshitkrnagpal)