problem description
error message:
Store does not have a valid reducer. Make sure the argument passed to combineReducers is an object whose values are reducers.
the environmental background of the problems and what methods you have tried
I put reducer with different functions under different folders, and then use redux-persist for data persistence. Will web projects be refreshed often, so I want to keep the data in store from being lost? however, merging reducer with combineReducers method is an error, and I don"t know why
related codes
/ / Please paste the code text below (do not replace the code with pictures)
reducer
import * as Pages from "./action-types";
let defaultValue = {
user_name: "",
user_id: ""
}
export default function UserInfo (state = defaultValue, action = {}) {
switch (action.type) {
case Pages.SAVEUSERINFO:
return { ...state,
...{
user_name: action.data.data.username,
user_id: action.data.data.id
}
};
default:
return state;
}
}
merge location
import {
combineReducers,
} from "redux";
import UserInfo from "./Pages/reducers";
import SaveInfo from "./Layout/reducers";
const rootReducer = combineReducers({
UserInfo,
SaveInfo
});
export default rootReducer;
entry file
import {
Provider
} from "react-redux";
import {
createStore,
applyMiddleware
} from "redux";
// Reducersreducer
import Reducers from "@/Reducers";
import thunk from "redux-thunk";
import {persistStore, persistCombineReducers} from "redux-persist";
import { PersistGate } from "redux-persist/es/integration/react";
import storage from "redux-persist/es/storage"
const config = {
key: "root",
storage,
};
function configureStore(){
console.log(Reducers)
let reducer = persistCombineReducers(config, Reducers);
let store = createStore(reducer, applyMiddleware(thunk));
let persistor = persistStore(store);
return { persistor, store }
}
const render = Component => {
const { persistor, store } = configureStore();
ReactDOM.render(
//redux
<Provider store={store}>
<PersistGate persistor={persistor}>
<Component />
</PersistGate>
</Provider>,
document.getElementById("app"),
)
}
what result do you expect? What is the error message actually seen?
expect that no matter how you refresh the browser, the data in the previous store can be saved to refresh
.