mirror of
https://github.com/streamich/react-use.git
synced 2025-12-08 18:02:14 +00:00
38 lines
649 B
Markdown
38 lines
649 B
Markdown
# `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)
|