'How to fix 'The previous state received by the reducer...'?
I load/update data in localStorage:
import thunk from "redux-thunk";
import {applyMiddleware, createStore} from "redux";
import {composeWithDevTools} from "redux-devtools-extension";
import reducers from "./reducers";
import {loadState, saveState} from "./localStorage";
const persistedState = loadState()
export const store = createStore(reducers, persistedState, composeWithDevTools(applyMiddleware(thunk)))
store.subscribe(() => saveState(store.getState().user.userId))
but I have error
The previous state received by the reducer has unexpected type of "string". Expected argument to be an object with the following keys: "user", "countries", "sortedCountries"
After deleting persistedState from createStore the error disappears
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|