# react-window-mixins

> React mixins for working with browser window events.

Latest version **0.0.7** (published 2016-04-15) · ISC license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.7 |
| Published | 2016-04-15 |
| First published | 2014-11-12 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 54 |
| Author | Szymon Kaliski |
| Maintainers | szymon_k |
| Keywords | react, react-mixin, browser, events |

## Links

- npm: https://www.npmjs.com/package/react-window-mixins
- Repository: https://github.com/szymonkaliski/react-window-mixins
- Issues: https://github.com/szymonkaliski/react-window-mixins/issues
- npm.io page: https://npm.io/package/react-window-mixins

## Dependencies (1)

- [lodash.throttle](https://npm.io/package/lodash.throttle.md) ^2.4.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

- 0.0.7 (latest) — 2016-04-15
- 0.0.6 — 2015-01-25
- 0.0.5 — 2014-12-22
- 0.0.4 — 2014-11-15
- 0.0.3 — 2014-11-12
- 0.0.2 — 2014-11-12
- 0.0.1 — 2014-11-12

## README

# react-window-mixins

React mixins for working with browser window events.

Both mixins are throttled not to hang your browser.

## Install

`npm install react-window-mixins`

## OnResize

Useful for calculating sizes for more complicated layouts, handling changes for for responsive layouts (sadly not everything is possible via CSS), etc...

```javascript
var OnResize = require("react-window-mixins").OnResize;

React.createClass({
  mixins: [ OnResize ],

  render: function() {
    return React.DOM.div(
      null,
      "current window size: " + this.state.window.width + ", " + this.state.window.height,
      "current document size: " + this.state.document.width + ", " + this.state.document.height
    );
  }
});
```

You can also write your own `onResize` handler:

```javascript
var OnResize = require("react-window-mixins").OnResize;

React.createClass({
  mixins: [ OnResize ],

  onResize: function() {
    this.setState({
      componentWidth: this.getDOMNode().clientWidth
    });
  },

  render: function() {
    return React.DOM.div(
      null,
      "current component width: " + this.state.componentWidth
    );
  }
});
```

## OnScroll

Useful for elements interacting with scroll position, and even writing parallax websites with React.

```javascript
var OnScroll = require("react-window-mixins").OnScroll;

React.createClass({
  mixins: [ OnScroll ],

  render: function() {
    return React.DOM.div(
      null,
      "current scroll offset: " + this.state.scroll.x + ", " + this.state.scroll.y
    );
  }
});
```

You can also write your own `onScroll` handler:

```javascript
var OnScroll = require("react-window-mixins").OnScroll;

React.createClass({
  mixins: [ OnScroll ],

  onScroll: function() {
    this.setState({ 
      scrollPosition: window.pageYOffset - this.getDOMNode().offsetTop 
    });
  },

  render: function() {
    return React.DOM.div(
      null,
      "current component scroll offset: " + this.state.scrollPosition
    );
  }
});
```

## OnUnload

Useful for defining handlers for the `unload` and `beforeunload` events. Event
handlers are only added to the `window` if they are defined. No default handlers
are added automatically.

```javascript
var OnUnload = require("react-window-mixins").OnUnload;

React.createClass({
  mixins: [ OnUnload ],

  onUnload: function() {
    // Clean up any resources
  },

  onBeforeUnload: function() {
    return 'Are you sure you want to leave the page?';
  }
});
```

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