ngrx-store-localstorage icon indicating copy to clipboard operation
ngrx-store-localstorage copied to clipboard

Rehydrate adds a root state element to my store

Open fskaeh opened this issue 5 years ago • 0 comments

I have an app where the state is shaped like this;

{ locations: { searchLocations: [...] editLocation: {...} } }

For this state, I have an ActionReducerMap passed in StoreModule.forRoot in AppModule: export const reducers: ActionReducerMap<IAppState> = { locations: fromLocations.reducer }; export function reducer(state: ILocationsState | undefined, action: Action) { return locationsReducer(state, action); }

I set up ngrx-store-localstorage like this: export function localStorageSyncReducer(reducer: ActionReducer<any>): ActionReducer<any> { return localStorageSync({ keys: ['state'], rehydrate: true })(reducer); }

Now in my localStorage I have a key 'state' whose value is a JSON object of the expected format. When my app starts, the state is properly recovered from localStorage but it is put under "state" in my store, giving something like this: { state: { locations: { searchLocations: [DATA FROM LOCALSTORAGE] editLocation: {DATA FROM LOCALSTORAGE} } }, locations: { searchLocations: [EMPTY], editLocation: {null} } }

I don't understand why the object recovered from localStorage isn't set as the root level of my store.

fskaeh avatar Jun 14 '19 13:06 fskaeh