I am working on a react app and recently upgraded to node12.10.0 on my mac and have seen a plethora of package issues. I upgraded a lot of the packages in my project but am down to an error that seems to occur when I call persistor.purge():
TypeError: Cannot read property 'getItem' of undefined
getStoredState
node_modules/redux-persist/es/getStoredState.js:19
16 | deserialize = defaultDeserialize;
17 | }
18 |
> 19 | return storage.getItem(storageKey).then(function (serialized) {
20 | if (!serialized) return undefined;else {
21 | try {
22 | var state = {};
View compiled
Object../src/index.js
src/index.js:26
23 | debugger;
24 | debugger;
25 |
> 26 | getStoredState({}).then((err, restoredState) => {
27 | if(restoredState) {
28 | let storedAppVersion = restoredState.app ? restoredState.app.version : null;
29 | // Purge the persisted state if the version has changed
The error itself seems to occur when I hit persistor.purge() in the following reducer code:
case REHYDRATE:
let isValid = isTokenInLocalStorageValid();
if(isValid) {
let storedState = action.payload.user;
let newState = Object.assign({}, storedState, { status: null });
return newState;
}
debugger;
debugger;
persistor.purge();
Here is the code where I am creating the peristor and the store:
export const history = createBrowserHistory();
const sagaMiddleware = createSagaMiddleware();
const initialState = {}
const middleware = [
thunk,
sagaMiddleware,
routerMiddleware(history)
]
const composedEnhancers = compose(
applyMiddleware(...middleware)
)
debugger;
debugger;
const persistConfig = {
key: 'root',
storage: localforage,
}
const persistedReducer = persistReducer(persistConfig, rootReducer(history));
const store = createStore(
persistedReducer,
initialState,
composedEnhancers
)
store.runSaga = sagaMiddleware.run(sagas);
let persistor = persistStore(store)
export default () => {
return { store, persistor }
}
I reviewed the setup examples and am not seeing where the issue could be.