Using Redux in angular 5 how do I get the browser to remember the previous save state on refresh

核能气质少年 提交于 2019-11-28 06:28:51

问题


Currently, on refresh, I loose the saved state.

I'm not sure if I need to do anything in the app module.

I'm using angular5, typescript, webpack with ng2-Redux and Redux.

This is my current app module class:

export class AppModule {
  constructor(ngRedux: NgRedux<IAppState>) {
    ngRedux.configureStore(rootReducer, INITIAL_APP_STATE, [ createLogger() ]);
  }
}

I'm not sure if I need to getState on load of the app. Currently the default INITIAL_APP_STATE is always set thus loosing the stores state in the browsers memory.


回答1:


It's the normal behavior of the redux, you can try to save your state to a cookie or localstorage and load it on initialisation.

To save state to local storage after each update, you need to create a global reducer that saves the state. (it can cost a lots of CPU if you have a big state)



来源:https://stackoverflow.com/questions/49008341/using-redux-in-angular-5-how-do-i-get-the-browser-to-remember-the-previous-save

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!