I'm using Metronic theme to build a React application. v7
By default metronic uses redux Saga. I'm not familiar with Saga. I know thunk. So I tried to modify the code but I'm stuck at the splash screen.
here is the default code that uses Saga:
store.js
import {configureStore, getDefaultMiddleware} from "@reduxjs/toolkit";
import createSagaMiddleware from "redux-saga";
import {reduxBatch} from "@manaflair/redux-batch";
import {persistStore} from "redux-persist";
import {rootReducer, rootSaga} from "./rootReducer";
const sagaMiddleware = createSagaMiddleware();
const middleware = [
...getDefaultMiddleware({
immutableCheck: false,
serializableCheck: false,
thunk: true
}),
sagaMiddleware
];
const store = configureStore({
reducer: rootReducer,
middleware,
devTools: process.env.NODE_ENV !== "production",
enhancers: [reduxBatch]
});
export const persistor = persistStore(store);
sagaMiddleware.run(rootSaga);
export default store;
index.js (remains unchanged except for the store import location)
ReactDOM.render(
<MetronicI18nProvider>
<MetronicLayoutProvider>
<MetronicSubheaderProvider>
<MetronicSplashScreenProvider>
<App store = {store} persistor = {persistor} basename = {PUBLIC_URL}/>
</MetronicSplashScreenProvider>
</MetronicSubheaderProvider>
</MetronicLayoutProvider>
</MetronicI18nProvider>,
document.getElementById("root")
);
RootReducer.js:
import {all} from "redux-saga/effects";
import {combineReducers} from "redux";
import * as auth from "../app/modules/Auth/_redux/authRedux";
import {customersSlice} from "../app/modules/ECommerce/_redux/customers/customersSlice";
import {productsSlice} from "../app/modules/ECommerce/_redux/products/productsSlice";
import {remarksSlice} from "../app/modules/ECommerce/_redux/remarks/remarksSlice";
import {specificationsSlice} from "../app/modules/ECommerce/_redux/specifications/specificationsSlice";
export const rootReducer = combineReducers({
auth: auth.reducer,
customers: customersSlice.reducer,
products: productsSlice.reducer,
remarks: remarksSlice.reducer,
specifications: specificationsSlice.reducer
// TODO add Reducers here
});
export function* rootSaga() {
yield all([auth.saga()]);
}
I change it to: store.js
import {persistStore} from "redux-persist";
import {applyMiddleware, combineReducers, compose, createStore} from "redux";
import thunk from "redux-thunk";
import technologyReducer from "./reducers/technologyRed";
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
const rootReducer = combineReducers({
technology: technologyReducer
});
const store = createStore(rootReducer, composeEnhancers(applyMiddleware(thunk)));
export const persistor = persistStore(store);
export default store;
Can You help me use thunk instead of saga in Metronic?