# react-resize-context

> A high performance React component for responding to resize event

Latest version **3.0.0** (published 2019-03-22) · MIT license · 0 weekly downloads

## Install

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

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2019-03-22 |
| First published | 2018-07-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 17.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 22 |
| Author | LeetCode front-end team |
| Maintainers | runjuuu |
| Keywords | react, resize, detector |

## Links

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

## Dependencies (4)

- [lodash](https://npm.io/package/lodash.md) ^4.17.10
- [fastdom](https://npm.io/package/fastdom.md) ^1.0.9
- [shallowequal](https://npm.io/package/shallowequal.md) ^1.1.0
- [element-resize-detector](https://npm.io/package/element-resize-detector.md) ^1.1.14

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

- 3.0.0 (latest) — 2019-03-22
- 2.0.0 — 2018-11-15
- 1.1.1 — 2018-11-14
- 1.1.0 — 2018-09-01
- 1.0.2 — 2018-08-25
- 1.0.1 — 2018-08-25
- 1.0.0 — 2018-07-30
- 0.2.1 — 2018-07-29
- 0.2.0 — 2018-07-29
- 0.1.5 — 2018-07-29
- 0.1.4 — 2018-07-29
- 0.1.3 — 2018-07-29
- 0.1.2 — 2018-07-29
- 0.1.1 — 2018-07-29
- 0.1.0 — 2018-07-29

## README

# react-resize-context

[![npm version](https://badge.fury.io/js/react-resize-context.svg)](https://www.npmjs.com/package/react-resize-context)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/LeetCode-OpenSource/react-resize-context/pulls)
[![MIT Licence](https://badges.frapsoft.com/os/mit/mit.svg?v=103)](https://opensource.org/licenses/mit-license.php)

A high performance React component for responding to resize event.

### Install
```bash
npm install react-resize-context
```

## Examples
* [A simple example](https://codesandbox.io/embed/jjjmp4z6yy)
* [Multiple components listen resize event from the same parent element](https://codesandbox.io/embed/vnz20v4j65)

## APIs
Provides a `{ ResizeProvider, ResizeConsumer }` pair which just like React's [Context API](https://reactjs.org/docs/context.html). When renders a context `ResizeConsumer`, it will listen to the resize event from the [children](https://reactjs.org/docs/jsx-in-depth.html#children-in-jsx) of closest matching `ResizeProvider` above it in the tree.

### \<ResizeProvider \/\>
> A React component that allows `ResizeConsumer` to listen to the resize event from `ResizeProvider`'s children element.

### \<ResizeConsumer \/\>
> It is also a React component that triggers two callback functions when the element is resized. One is `onSizeChanged` and the other is `updateDatasetBySize`.
```typescript
interface Size {
  width: number;
  height: number;
}

interface DOMStringMap {
    [name: string]: string | undefined;
}

type onSizeChanged =  (size: Size) => void;
type updateDatasetBySize = (size: Size) => DOMStringMap;
```

#### About `updateDatasetBySize`
The return value of `updateDatasetBySize` is updated to the [dataset](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset) of the current ResizeConsumer's DOM element, so we can easily update the styles of different sizes through the CSS attribute selectors (eg: `[data-size="small"]`).

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