本文介绍了不推荐使用警告消息“getDefaultMiddleware"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在更新 "@reduxjs/toolkit" 后收到
那么我应该如何删除这个警告.我们还有其他方法可以在 getDefaultMiddleware
is deprecated 警告:"^1.6.1"configureStore
函数中注入默认中间件吗?
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;
}
感谢任何帮助,谢谢!
推荐答案
configureStore
中的 middleware
选项接受一个回调函数,该回调将被赋予 getDefaultMiddleware
作为它的参数:
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.
这篇关于不推荐使用警告消息“getDefaultMiddleware"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!