# react-resize-aware

> A React hook that makes it possible to listen to element resize events.

Latest version **4.1.0** (published 2025-10-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-resize-aware
pnpm add react-resize-aware
yarn add react-resize-aware
bun add react-resize-aware
```

## Health

**Score 50/100 (C)** — status: stable.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 4.1.0 |
| Published | 2025-10-23 |
| First published | 2016-05-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 31.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 563 |
| Author | Federico Zivolo |
| Maintainers | fezvrasta |
| Keywords | react, resize, element, queries, media, query, element, query, react-component |

## Links

- npm: https://www.npmjs.com/package/react-resize-aware
- Repository: https://github.com/FezVrasta/react-resize-aware
- Homepage: https://github.com/FezVrasta/react-resize-aware#readme
- Issues: https://github.com/FezVrasta/react-resize-aware/issues
- npm.io page: https://npm.io/package/react-resize-aware

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 4.1.0 (latest) — 2025-10-23
- 3.1.1-issue-58.1 (issue-58) — 2022-02-08
- 3.0.0-beta.4 (beta) — 2019-06-12
- 4.0.0 — 2024-03-22
- 3.1.3 — 2024-03-20
- 3.1.2 — 2022-10-27
- 3.1.1-issue-58 — 2022-02-07
- 3.1.1 — 2021-09-02
- 3.1.0 — 2020-11-14
- 3.0.1 — 2020-06-03
- 3.0.0 — 2019-12-13
- 3.0.0-beta.7 — 2019-10-17
- 3.0.0-beta.6 — 2019-10-08
- 3.0.0-beta.5 — 2019-10-07
- 3.0.0-beta.3 — 2019-03-12
- … 29 more at https://npm.io/package/react-resize-aware/versions

## README

# react-resize-aware

It does one thing, it does it well: listens to resize events on any HTML element.

`react-resize-aware` is a zero dependency, **~600 bytes** [React Hook](https://reactjs.org/docs/hooks-reference.html) you can use to detect resize events without relying on intervals, loops, DOM manipulation detection or CSS redraws.

**It takes advantage of the `resize` event on the `HTMLObjectElement`, works on any browser I know of, and it's super lightweight.**

In addition, it doesn't directly alters the DOM, everything is handled by React.

> Looking for the 2.0 docs? [Click here](https://github.com/FezVrasta/react-resize-aware/tree/v2.7.2)

## Installation

```
yarn add react-resize-aware
```

or with npm:

```
npm install --save react-resize-aware
```

## Usage

The API is simple yet powerful, the `useResizeAware` [Hook](https://reactjs.org/docs/hooks-reference.html)
returns a React node you will place inside the measured element, and an object containing its sizes:

```jsx
import React from "react";
import useResizeAware from "react-resize-aware";

const App = () => {
  const [resizeListener, sizes] = useResizeAware();

  return (
    <div style={{ position: "relative" }}>
      {resizeListener}
      Your content here. (div sizes are {sizes?.width} x {sizes?.height})
    </div>
  );
};
```

> **Heads up!**: Make sure to assign a `position != initial` to the HTMLElement you want to target (`relative`, `absolute`, or `fixed` will work).

## API

The Hook returns an array with two elements inside:

### `[resizeListener, ...]` (first element)

This is an invisible React node that must be placed as direct-child of the HTMLElement you want to listen the resize events of.

The node is not going to interfer with your layouts, I promise.

### `[..., sizes]` (second element)

This object contains the `width` and `height` properties, it could be `null` if the element is not yet rendered.

## Custom `reporter`

You can customize the properties of the `sizes` object by passing a custom `reporter` function as first argument of `useResizeAware`.

```tsx
const customReporter = (target: ?HTMLIFrameElement) => ({
  clientWidth: target != null ? target.clientWidth : 0,
});

const [resizeListener, sizes] = useResizeAware(customReporter);

return (
  <div style={{ position: "relative" }}>
    {resizeListener}
    Your content here. (div clientWidth is {sizes.clientWidth})
  </div>
);
```

The above example will report the `clientWidth` rather than the default `offsetWidth` and `offsetHeight`.

## React to size variations

For completeness, below you can find an example to show how to make your code react to size variations using React Hooks:

```jsx
const App = () => {
  const [resizeListener, sizes] = useResizeAware();

  React.useEffect(() => {
    console.log("Do something with the new size values");
  }, [sizes.width, sizes.height]);

  return (
    <div style={{ position: "relative" }}>
      {resizeListener}
      Your content here.
    </div>
  );
};
```

---
_Source: https://npm.io/package/react-resize-aware · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
