1.0.2 • Published 7 years ago

redux-window v1.0.2

Weekly downloads
32
License
MIT
Repository
github
Last release
7 years ago

redux-window

This is a small package to store the browser window's width and height in state.

Getting started

Install:

npm install --save redux-window

Add the reduxWindow reducer:

import { combineReducers } from 'redux';
import reduxWindow from 'redux-window';

const reducers = combineReducers({
  reduxWindow,
  ...other reducers
});

Then in index.js, import resizeEvent and pass it your store:

import { resizeEvent } from 'redux-window';
import store from './store';

resizeEvent(store);

Optional throttle on dispatch

The resize event is throttled to allow dispatch to be fired a maximum of once every 200ms. To change the default wait time, pass a second parameter to resizeEvent.

resizeEvent(store, 500);

Selectors

To get the window width and height from state:

import { getWidth, getHeight } from 'redux-window';

function mapStateToProps(state, ownProps) {
  return {
    width: getWidth(state),
    height: getHeight(state),
  };
}

NOTE: the selectors require your reducer to use the key reduxWindow, as in the example above.

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.1.8

7 years ago

0.1.7

7 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago