Files
super-app/App/common/redux/store.js
2024-03-27 15:06:03 +00:00

29 lines
850 B
JavaScript

import { applyMiddleware, configureStore, getDefaultMiddleware } from "@reduxjs/toolkit";
import rootReducer from "./rootReducer";
import thunk from "redux-thunk";
import AsyncStorage from "@react-native-async-storage/async-storage";
import { persistReducer, persistStore } from "redux-persist";
const middleWares = [getDefaultMiddleware({
thunk: true,
serializableCheck: false
}
)];
const persistConfig = {
key: "root",
storage: AsyncStorage,
};
const persistedReducer = persistReducer(persistConfig, rootReducer);
export default () => {
//by default configureStore has middleware thunk in it, it is added explicitly below for ref to add other middlewares
let store = configureStore(
{ reducer: persistedReducer },
applyMiddleware(...middleWares)
);
let persistor = persistStore(store);
return { store, persistor };
};