Skip to content
This repository has been archived by the owner on Feb 15, 2021. It is now read-only.
/ redux-window Public archive

Responsivelly set browser window size in redux state

Notifications You must be signed in to change notification settings

bdmason/redux-window

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Responsivelly set browser window size in redux state

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published