# use-window-size-v2

> Custom hook to obtain the current window size in React apps.

Latest version **2.2.5** (published 2023-08-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install use-window-size-v2
pnpm add use-window-size-v2
yarn add use-window-size-v2
bun add use-window-size-v2
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.2.5 |
| Published | 2023-08-14 |
| First published | 2022-07-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Jason Jin |
| Maintainers | jasonjin220 |
| Keywords | react, hook, react hook, typescript, window size, window-size, usewindowsize, use-window-size |

## Links

- npm: https://www.npmjs.com/package/use-window-size-v2
- Repository: https://github.com/jasonjin220/use-window-size-v2
- Issues: https://github.com/jasonjin220/use-window-size-v2/issues
- npm.io page: https://npm.io/package/use-window-size-v2

## 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

- 2.2.5 (latest) — 2023-08-14
- 2.2.4 — 2023-07-12
- 2.2.3 — 2023-06-07
- 2.2.2 — 2023-06-06
- 2.2.1 — 2023-06-06
- 2.2.0 — 2023-06-06
- 2.1.0 — 2023-06-06
- 2.0.5 — 2023-05-15
- 2.0.4 — 2023-05-04
- 2.0.3 — 2022-12-08
- 2.0.2 — 2022-08-15
- 2.0.1 — 2022-08-11
- 2.0.0 — 2022-07-19

## README

# useWindowSize()

[![Node version](https://img.shields.io/npm/v/use-window-size-v2.svg?style=flat)](https://www.npmjs.com/package/use-window-size-v2)
[![NPM total downloads](https://img.shields.io/npm/dt/use-window-size-v2.svg?style=flat)](https://npmcharts.com/compare/use-window-size-v2?minimal=true)
[![npm bundle size (minified)](https://img.shields.io/bundlephobia/minzip/use-window-size-v2@2.2.4.svg)](https://bundlephobia.com/result?p=use-window-size-v2)
![NPM license](https://img.shields.io/npm/l/use-window-size-v2.svg?style=flat)

React hook to obtain the current window size in React apps.

useWindowSize() automatically updates width and height values when screen size changes. You can get your application window's width and height like this:

```jsx
const { width, height } = useWindowSize();
```

## Installation

```sh
npm install use-window-size-v2
```

or

```sh
yarn add use-window-size-v2
```

## Usage

This hook returns the current width and height of the window. It is **debounced**, meaning it will wait `delay` milliseconds (0ms by default) for the resize events to stop firing before it actually updates its state with the new width and height.

### Parameter (optional)

| Key     | Type   | Default | Description                                                                                                                        |
| ------- | ------ | ------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| `delay` | number | `0`     | The amount of time in milliseconds you want to wait after the latest resize event before updating the size of the window in state. |

### Return object

|        | Type     | Description                        |
| ------ | -------- | ---------------------------------- |
| width  | `number` | The current `width` of the window  |
| height | `number` | The current `height` of the window |

## Example

[![Edit react-hook-usewindowsize](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/use-window-size-v2-w85fs5)

```jsx
import useWindowSize from "use-window-size-v2";

const App = () => {
  const { width, height } = useWindowSize(100); // wait 100ms for the resize events

  return (
    <div>
      <p>Window Width: {width}px</p>
      <p>Window Height: {height}px</p>
    </div>
  );
};

export default App;
```

---
_Source: https://npm.io/package/use-window-size-v2 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
