-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
52 lines (45 loc) · 1.45 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import {
Action,
configureStore,
EnhancedStore,
ThunkAction,
} from "@reduxjs/toolkit";
import createSagaMiddleware from "redux-saga";
import loggedInUserReducer from "../../features/auth/redux/authSlice";
import { bandApi } from "../../features/band/redux/bandApi";
import { showApi } from "../../features/tickets/redux/showApi";
import ticketReducer from "../../features/tickets/redux/ticketSlice";
import toastReducer from "../../features/toast/redux/toastSlice";
import { rootSaga } from "./sagas";
export const configureStoreWithMiddlewares = (
initialState = {}
): EnhancedStore => {
const sagaMiddleware = createSagaMiddleware();
const store = configureStore({
reducer: {
user: loggedInUserReducer,
tickets: ticketReducer,
toast: toastReducer,
[showApi.reducerPath]: showApi.reducer,
[bandApi.reducerPath]: bandApi.reducer,
},
middleware: (getDefaultMiddleware) =>
getDefaultMiddleware()
.prepend(sagaMiddleware)
.concat(showApi.middleware)
.concat(bandApi.middleware),
preloadedState: initialState,
devTools: process.env.NODE_ENV !== "production",
});
sagaMiddleware.run(rootSaga);
return store;
};
export const store = configureStoreWithMiddlewares();
export type AppDispatch = typeof store.dispatch;
export type RootState = ReturnType<typeof store.getState>;
export type AppThunk<ReturnType = void> = ThunkAction<
ReturnType,
RootState,
unknown,
Action<string>
>;