react-redux-starter-kit icon indicating copy to clipboard operation
react-redux-starter-kit copied to clipboard

[Question] How to deal with the reducers when I refresh the SPA web pages?

Open minhuaF opened this issue 7 years ago • 2 comments

hello , When I use this kit to create the SAP application, I find that if i refresh the web page , the reducers which i create before this route will disappear , so I have to create those reducers one more again in this route to prevent refreshing . Our data api are somthing different , there is not each route has independent data source. So, I want to know there any other way to deal with the reducers when refresh, or I am not get the important point in this kit. Thank you.

minhuaF avatar May 03 '17 07:05 minhuaF

@minhuaF If your app shares data across routes you will need to import the "common" reducer into reducers.js. Example below:

import usersReducer from './usersReducer';

export const makeRootReducer = (asyncReducers) => {
  return combineReducers({
    location: locationReducer,
    users: usersReducer,
    ...asyncReducers
  })
}

ascension avatar Jun 01 '17 04:06 ascension

Above is perfectly valid solutions, besides that reloading the web page (i.e. via refresh or whatever) will reset the redux store, so you will need to re-hydrate it either from some server stored state or local storage.

synchu avatar Jun 18 '17 05:06 synchu