Skip to content

Instantly share code, notes, and snippets.

@morizotter
Created April 20, 2016 09:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morizotter/81dbc2cccb91086fc490248178270da0 to your computer and use it in GitHub Desktop.
Save morizotter/81dbc2cccb91086fc490248178270da0 to your computer and use it in GitHub Desktop.
React+Reduxをした時のwindowサイズの変更検知 ref: http://qiita.com/morizotter/items/db22f9f2507a65956bf9
export const changeScreenWidth = (width) => {
return {
type: 'CHANGE_SCREEN_WIDTH',
screenWidth: width,
};
};
const initialState = {
...
screenWidth: window.innerWidth,
};
const sampleApp = (state = initialState, action) => {
switch (action.type) {
...
case 'CHANGE_SCREEN_WIDTH':
return Object.assign({}, state, {
screenWidth: action.screenWidth,
});
default:
return state;
}
};
export default sampleApp;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment