ngrx-store-localstorage
ngrx-store-localstorage copied to clipboard
Rehydrate adds a root state element to my store
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.