# react-window-info-hook

> Window resize hook for React and TypeScript. Returns window size and simple responsive info.

Latest version **1.2.0** (published 2025-12-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-window-info-hook
pnpm add react-window-info-hook
yarn add react-window-info-hook
bun add react-window-info-hook
```

## Health

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

Positive: has types; no vulnerabilities; has provenance; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2025-12-24 |
| First published | 2019-05-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 8.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 0 |
| Author | Janne Hämäläinen |
| Maintainers | jannhama |
| Keywords | react, react-component, hook, window, resize, responsive, browser, typescript, size |

## Links

- npm: https://www.npmjs.com/package/react-window-info-hook
- Repository: https://github.com/jannhama/react-window-info-hook
- Homepage: https://github.com/jannhama/react-window-info-hook#readme
- Issues: https://github.com/jannhama/react-window-info-hook/issues
- npm.io page: https://npm.io/package/react-window-info-hook

## Dependencies (1)

- [react](https://npm.io/package/react.md) >=16.8.6

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

- 1.2.0 (latest) — 2025-12-24
- 1.1.0 — 2022-03-16
- 1.0.6 — 2019-12-11
- 1.0.5 — 2019-05-31
- 1.0.4 — 2019-05-31
- 1.0.3 — 2019-05-30
- 1.0.2 — 2019-05-30
- 1.0.1 — 2019-05-30
- 1.0.0 — 2019-05-30

## README

[![Build Status](https://dev.azure.com/janneahamalainen/janneahamalainen/_apis/build/status/jannhama.react-window-info-hook?branchName=master)](https://dev.azure.com/janneahamalainen/janneahamalainen/_build/latest?definitionId=1&branchName=master)

# react-window-info-hook
Window resize hook for React and TypeScript

This is a simple helper hook to get current browser window size on run time.
Typical use case would responsive web design with react. In the past CSS **display: none** used to hide
elements from the DOM as well but it doesn't behave like that anymore. Correct way to hide elements is just to
not render them at all.

## Install

```
npm install react-window-info-hook
```

## Usage

Usage is pretty straight forward. Just import the hook and call the hook function in your component.
In the example below _mobile_ div is shown if hook says window size is below mobile limit. Otherwise we render
_tablet_ div.

```ts
import {useWindowInfo} from 'react-window-info-hook'

export function MyReactComponent(): JSX.Element {
  const info = useWindowInfo();
  return (
    <>
      {info.mobile ? <div>Mobile</div> : <div>Tablet</div>}
    </>
  );
}

```

## Return values

Hook function will return you following structure

```ts
interface IWindowInfo {
  windowSize: { width: number, height: number };
  mobile: boolean;
  tablet: boolean;
  desktop: boolean;
  portrait: boolean;
}
```

Only one of the predefined modes can be true at time. Portrait will be true if window height is more than
window width.

## Responsive design & breakpoints

Currently display sizes are divided into following:

* Mobile - when window width is below 768 pixels
* Tablet - when window width is equal or above 768 pixels but less than 992 pixels
* Desktop - when window width is equal or above 992 pixels

Naturally more fine tuned breakpoints could be added but in the other hand that can be defined in the application
as hook returns also current size of window.

Breakpoint info was gathered from [Media Genesis site](https://mediag.com/blog/popular-screen-resolutions-designing-for-all/)

## Server side rendering (SSR)

Server side rendering crashed initial version of this component. This is now attempted to be fixed by checking if window exist.

## License 
Released under [MIT](https://opensource.org/licenses/MIT) license.

&copy; 2019-2025 Janne Hämäläinen.

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