Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rehydrate adds a root state element to my store #130

Open
fskaeh opened this issue Jun 14, 2019 · 0 comments
Open

Rehydrate adds a root state element to my store #130

fskaeh opened this issue Jun 14, 2019 · 0 comments

Comments

@fskaeh
Copy link

fskaeh commented Jun 14, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant