# ts-react-resize-listener

> React Resize Listener written in Typescript utilizing RxJS

Latest version **1.0.6** (published 2019-08-20) · ISC license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install ts-react-resize-listener
pnpm add ts-react-resize-listener
yarn add ts-react-resize-listener
bun add ts-react-resize-listener
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2019-08-20 |
| First published | 2019-07-09 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 11.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | kevin.d.krug@googlemail.com |
| Maintainers | kevin-krug |
| Keywords | React, Typescript, Resize, RxJS |

## Links

- npm: https://www.npmjs.com/package/ts-react-resize-listener
- Repository: https://github.com/kevin-krug/react-resize-listener
- Homepage: https://github.com/kevin-krug/react-resize-listener#readme
- Issues: https://github.com/kevin-krug/react-resize-listener/issues
- npm.io page: https://npm.io/package/ts-react-resize-listener

## Dependencies (2)

- [rxjs](https://npm.io/package/rxjs.md) ^6.5.2
- [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.0.6 (latest) — 2019-08-20
- 1.0.4 — 2019-08-05
- 1.0.3 — 2019-07-15
- 1.0.2 — 2019-07-15
- 1.0.1 — 2019-07-11
- 1.0.0 — 2019-07-09

## README

# TS React Resize Listener

A React component written in Typescript which abstracts resize handling. The resize handler will only be called after a distinct resize change and will be debounced to limit the execution rate (default debounce time is 250ms). A custom debounce time can be added as an optional prop individually for each component.

## Installation

`npm i ts-react-resize-listener`

## Usage / API

Simply render the ResizeListener Component as a child of the Component you would like to add resize handling to in your React project (written in jsx or tsx).

```jsx
import React, {Component} from 'react';
import ResizeListener from 'ts-react-resize-listener';

export default class ComponentWithResizeHandling extends Component<Props> {

	public render() {
		return (
			<div>
			    <ResizeListener
				    onResize={this.onResize}
				    debounce={100} />
				...
			</div>
		);
	}
	...

	private onResize = (windowInnerWidth) => {
		...
	};
}
```

### Props


| Prop | Description | Required | Default |
| :---         |     :---:      |     :---:      |         ---: |
| onResize | the resize handler; called with window inner width | true    | none
| debounce | the debounce time in milliseconds | false  | 250

## Performance

For performance reasons a singleton pattern is implemented to only register a single event listener (/create a single windowSize observable) for each individual debounce time shared among all components rendering
the ResizeListener component (with the same debounce value).

## Setup

`npm i`

## Tests

`npm run test`

## Contributing

is welcome!

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