Using Redux in angular 5 how do I get the browser

2019-01-27 06:30发布

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条回答
啃猪蹄的小仙女
2楼-- · 2019-01-27 07:06

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)

查看更多
登录 后发表回答