It appears that the error message is unknown but it seems like your code does not follow the correct syntax for adding additional middlewares in Typescript.
For more information on middleware, please refer to the middleware documentation.
Middleware Usage
To add custom middlewares, make use of the getDefaultMiddleware
function and return an array of middleware functions in Typescript.
If you do not provide this option, configureStore
will automatically use the middleware returned from getDefaultMiddleware
.
For detailed explanation and a list of default middleware, visit the getDefaultMiddleware
documentation page.
Tuple Instance
In Typescript, it is recommended to utilize a Tuple
instance when adding additional middleware for better type inference.
import { configureStore, Tuple } from '@reduxjs/toolkit'
configureStore({
reducer: rootReducer,
middleware: () => new Tuple(additionalMiddleware, logger),
})
Alternatively, JavaScript users can simply use a plain array if preferred.
If you want to include your own middleware, remember to return a Tuple
instance.
import { configureStore } from "@reduxjs/toolkit";
import { userAPI } from "./api/userAPI";
export const store = configureStore({
reducer: {
[userAPI.reducerPath]: userAPI.reducer,
},
middleware: () => new Tuple(userAPI.middleware),
});
To combine custom middlewares with default ones, you can use the concat
and prepend
methods from getDefaultMiddleware.
middleware: (getDefaultMiddleware) =>
getDefaultMiddleware().concat(userAPI.middleware),
If you have multiple middlewares to add, simply chain them using the same concat
or prepend
methods.
middleware: (getDefaultMiddleware) =>
getDefaultMiddleware()
.concat(
analytics,
logger,
userAPI.middleware,
// etc
),