File size: 649 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# `useSize`
React sensor hook that tracks size of an HTML element.
## Usage
```jsx
import {useSize} from 'react-use';
const Demo = () => {
const [sized, {width, height}] = useSize(
({width}) => <div style={{background: 'red'}}>Size me up! ({width}px)</div>,
{ width: 100, height: 100 }
);
return (
<div>
{sized}
<div>width: {width}</div>
<div>height: {height}</div>
</div>
);
};
```
## Reference
```js
useSize(element, initialSize);
```
- `element` — sized element.
- `initialSize` — initial size containing a `width` and `height` key.
## Related hooks
- [useMeasure](./useMeasure.md)
|