'redux persist sessioStorage not taking the data from session storage
I am using redux persist "redux-persist": "^6.0.0", i am setting the data on session storage instead of localStorage, data is stored correctly in sessionStorage, however my app does not seem to recognise the stored data on sessionStorage, when page refresh everything goes bak to state 0.
my store file for redux:
import { applyMiddleware, compose, createStore, combineReducers } from "redux";
import thunk from "redux-thunk";
import loginReducer from "./login/reducers";
import configReducer from "./config/reducers";
import { persistStore, persistReducer } from "redux-persist";
import storage from "redux-persist/lib/storage/session";
const persistConfig = {
key: "persist-key",
storage,
};
const rootReducer = combineReducers({
login: loginReducer,
config: configReducer,
});
const persistedReducer = persistReducer(persistConfig, rootReducer);
const middleware = [thunk];
const composeEnhancers = compose(applyMiddleware(...middleware));
const configureStore = () => {
return createStore(persistedReducer, composeEnhancers);
};
const store = configureStore();
const persistedData = persistStore(store);
export default store;
export { persistedData };
and I am consuming the data on my index.js
...
import store, { persistedData } from "./redux/store";
import { PersistGate } from "redux-persist/integration/react";
...
ReactDOM.render(
<React.StrictMode>
<Provider store={store}>
<PersistGate persistor={persistedData}>
<App />
</PersistGate>
</Provider>
</React.StrictMode>,
document.getElementById("root")
);
any idea what I am doing wrong here?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
