# react-window-sizer

> React HOC that passes the browser dimensions to another component

Latest version **1.0.1** (published 2018-02-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-window-sizer
pnpm add react-window-sizer
yarn add react-window-sizer
bun add react-window-sizer
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2018-02-07 |
| First published | 2018-02-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 188.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Justin Mak |
| Maintainers | aka.jmak |
| Keywords | react, react-component, hoc, window, size |

## Links

- npm: https://www.npmjs.com/package/react-window-sizer
- Homepage: https://github.com/jmakGH/react-window-sizer
- Issues: https://github.com/jmakGH/react-window-sizer/issues
- npm.io page: https://npm.io/package/react-window-sizer

## Dependencies (3)

- [prop-types](https://npm.io/package/prop-types.md) ^15.6.0
- [lodash.debounce](https://npm.io/package/lodash.debounce.md) ^4.0.8
- [lodash.throttle](https://npm.io/package/lodash.throttle.md) ^4.1.1

## 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.0.1 (latest) — 2018-02-07
- 1.0.0 — 2018-02-07

## README

# react-window-sizer

A higher-order React component that passes the browser's window dimensions.

[![Build Status](https://api.travis-ci.org/jmakGH/react-window-sizer.svg?branch=master)](https://travis-ci.org/jmakGH/react-window-sizer)
[![Coverage Status](https://coveralls.io/repos/github/jmakGH/react-window-sizer/badge.svg?branch=master)](https://coveralls.io/github/jmakGH/react-window-sizer?branch=master)

## Table of Contents
  * [Installation](#installation)
  * [Usage](#usage)
  * [Props](#props)

## Installation

To install, you can use [npm](https://www.npmjs.com/) or [yarn](https://yarnpkg.com).

```
$ npm install react-window-sizer
$ yarn add react-window-sizer
``` 

## Usage

The WindowSizer component has one required prop:
  * ```children``` which must be a function that this component will inject the
  browser's dimensions into.

Example:

```jsx
<WindowSizer>
  {({height, width}) => (
    <SomeComponent style={{height, width}} />
  )}
</WindowSizer>
```

### Optimizing the resize event

You can optimize the resize handler by specifying whether or not to throttle or
debounce it through the ```optimizeBy``` prop.

The component defaults to not optimize, but you can opt in by passing in a string
value of either ```'debounce'``` or ```'throttle'```.

This can be more fine-tuned by also specifying a wait duration through the
```optimizeEvery``` prop. This throttles the handler's invocation in milliseconds.

Example:

```jsx
<WindowSizer optimizeBy="debounce" optimizeEvery={300}>
  {({height, width}) => (
    <SomeComponent style={{height, width}} />
  )}
</WindowSizer>
```
> This will debounce the resize event handler every 300ms.

### Resize event callback

You can pass in a callback that will be invoked whenever the resize event handler
is called through the ```onResize``` prop.

The original event object and the browser's current window dimensions are passed
to the callback.

Example:

```jsx
function handleResize(e, dimensions) {
  // ...do something
}

<WindowSizer onResize={handleResize}>
  {({height, width}) => (
    <SomeComponent style={{height, width}} />
  )}
</WindowSizer>
```

## Props

| Name          | Required? | Type     | Default        |
| ------------- | --------- | -------- | -------------- |
| children      | Yes       | function |                |
| onResize      |           | function | ```() => {}``` |
| optimizeBy    |           | string   | ```''```       |
| optimizeEvery |           | number   | ```250```      |

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