Skip to content

Commit

Permalink
Use middleware callback
Browse files Browse the repository at this point in the history
  • Loading branch information
cschleiden committed Mar 7, 2023
1 parent 3ca5210 commit 8b0423b
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions src/store.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import {
Action,
configureStore,
DeepPartial,
ThunkAction,
configureStore,
getDefaultMiddleware,
} from "@reduxjs/toolkit";
import { NextComponentType, NextPageContext } from "next";
import rootReducer, { IState } from "./reducers";

import { useSelector } from "react-redux";
import { loadingBarMiddleware } from "react-redux-loading-bar";
import { createClient } from "./clients/clientFactory";
import { getSignalRClient } from "./clients/signalrFactory";
import { loadingBarMiddleware } from "react-redux-loading-bar";
import { useSelector } from "react-redux";

const extraArgument = {
createClient: createClient,
Expand Down Expand Up @@ -39,25 +38,31 @@ export interface InitialState {
}

function createStore(initialState?: DeepPartial<IState>) {
const middleware = [
...getDefaultMiddleware({
thunk: {
extraArgument,
},
}),
];

middleware.push(
loadingBarMiddleware({
promiseTypeSuffixes: ["/pending", "/fulfilled", "/rejected"],
})
);

return configureStore({
reducer: rootReducer,
devTools: true,
preloadedState: initialState,
middleware,
//preloadedState: initialState,
middleware: (getDefaultMiddleware) => {
const middleware = [
...getDefaultMiddleware({
thunk: {
extraArgument,
},
}),
];

middleware.push(
loadingBarMiddleware({
promiseTypeSuffixes: [
"/pending",
"/fulfilled",
"/rejected",
],
})
);

return middleware;
},
});
}

Expand Down

0 comments on commit 8b0423b

Please sign in to comment.