I am getting this error when I try to setup redux-persist to work with my React Native app. "baseReducer is not a function. (In 'baseReducer(state, action)', 'baseReducer' is undefined)"
// configureStore.js
import { createStore, applyMiddleware, compose } from 'redux';
import { persistStore, persistReducer, autoRehydrate } from 'redux-persist';
import storage from 'redux-persist/lib/storage'; // defaults to localStorage for web and AsyncStorage for react-native
import thunkMiddleware from "redux-thunk";
import rootReducer from './'
const persistConfig = {
key: 'root',
storage,
}
const persistedReducer = persistReducer(persistConfig, rootReducer);
const store = createStore(
persistedReducer,
{},
compose(
applyMiddleware(thunkMiddleware)
)
)
const persistor = persistStore(store)
export default { store, persistor }
//index.js
import { combineReducers } from "redux";
import stateReducer from "./appState";
import leadsReducer from "./leads";
import propertyReducer from "./property";
import userReducer from "./user";
import questionsReducer from "./questions";
import openHouseReducer from "./openHouse";
import pinReducer from "./pinReducer";
import houseImageReducer from "./houseImageReducer";
import searchReducer from "./search";
import switchReducer from './switchState';
import configureStore from './configureStore';
const rootReducer = combineReducers({
appState: stateReducer,
questions: questionsReducer,
property: propertyReducer,
search: searchReducer,
user: userReducer,
leads: leadsReducer,
openHouse: openHouseReducer,
pin: pinReducer,
houseImage: houseImageReducer,
switchState: switchReducer
});
export default rootReducer;
md5-cb783c440f226311c96113ec94db303d
//App.js
import './ReactotronConfig';
import React, { Component } from "react";
import { Provider, connect } from "react-redux";
import { createStore, combineReducers, applyMiddleware } from "redux";
import Routes from './navigators/Routes'
import reducers from "./reducers";
import thunkMiddleware from "redux-thunk";
import { PersistGate } from 'redux-persist/integration/react';
import {store, persistor} from './reducers/configureStore';
// const createStoreWithMiddleware = applyMiddleware(thunkMiddleware)(createStore);
// const store = Reactotron.createStore(rootReducer, compose(applyMiddleware(thunkMiddleware)))
class App extends Component {
render() {
return (
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<Routes />
</PersistGate>
</Provider>
);
}
}
export default App;
real problem was in configureStore.js had to export const store and export const persistor. instead of export default { store, persistor }
瀵煎嚭鐨勬椂鍊欓渶瑕佸鍑虹敓鎴愮殑persitor鍜宻tore
I have tried, both did not work. I keep getting the same error. (TypeError: Cannot read property 'getState' of undefined)
`// import { createForms } from 'react-redux-form'
import { applyMiddleware, createStore } from 'redux';
import logger from 'redux-logger';
import { persistReducer, persistStore } from 'redux-persist';
import storage from 'redux-persist/es/storage';
import thunk from 'redux-thunk';
import { questionsReducer } from '../redux/reducer';
const config = {
key: 'root',
storage,
debug: true,
blacklist: ['navigation'], // navigation will not be persisted
};
const pReducer = persistReducer(config, {questionsReducer});
const middleware = applyMiddleware(thunk, logger);
// did not work
export default () => {
const store = createStore(pReducer, middleware);
const persistor = persistStore(store);
return { store, persistor };
};
// did not work
export const store = createStore(pReducer, middleware);
export const persistor = persistStore(store);
`
Most helpful comment
real problem was in configureStore.js had to export const store and export const persistor. instead of export default { store, persistor }