I am getting a getDefaultMiddleware
is deprecated warning after updating "@reduxjs/toolkit": "^1.6.1"
So how should I remove this warning. Do we have any other way to inject default middleware in the configureStore
function?
import { configureStore, getDefaultMiddleware } from "@reduxjs/toolkit";
import reducer from "./reducer";
import api from "./middleware/api";
export default function storeConfigure() {
const store = configureStore({
reducer,
middleware: [
...getDefaultMiddleware(),
api
],
});
return store;
}
Any help is appreciated thanks!
As part of that, getDefaultMiddleware includes some middleware that are added in development builds of your app only to provide runtime checks for two common issues: Immutability check middleware: deeply compares state values for mutations.
Redux Toolkit is our official, opinionated, batteries-included toolset for efficient Redux development. It is intended to be the standard way to write Redux logic, and we strongly recommend that you use it.
getDefaultMiddleware was originally just a separate export - we added the callback form of the middleware option that receives getDefaultMiddleware as its argument later. That callback completely supersedes the reason to use the imported version
One of the goals of Redux Toolkit is to provide opinionated defaults and prevent common mistakes. As part of that, getDefaultMiddleware includes some middleware that are added in development builds of your app only to provide runtime checks for two common issues:
The middleware option in configureStore accepts a callback function, and that callback will be given getDefaultMiddleware as its argument: const store = configureStore ( { reducer: rootReducer, middleware: (getDefaultMiddleware) => getDefaultMiddleware ().concat (logger), })
By default, configureStore adds some middleware to the Redux store setup automatically. If you want to customize the list of middleware, you can supply an array of middleware functions to configureStore:
The middleware
option in configureStore
accepts a callback function, and that callback will be given getDefaultMiddleware
as its argument:
const store = configureStore({
reducer: rootReducer,
middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(logger),
})
Use that instead of the separately imported version.
Can use like that:
const store = configureStore({
reducer,
middleware: (getDefaultMiddleware) => [...getDefaultMiddleware(), api],
})
A callback return an array of middle ware, it's will be cleaner and easy to read.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With