问题描述
错误图像好的,所以我正在开始一个新项目,这是我第一次遇到这种情况/我不断收到错误说明 ×类型错误:中间件不是我检查过依赖项的函数,我的代码看起来一切正常,没有任何问题,请帮忙
image of the ERROROK so I'm starting a new project and this is the first time that this has happened to me/ I keep getting an error stating ×TypeError: middleware is not a function i checked dependencies and everything seems fine gone over my code nothing seems wrong please help
我尝试删除模块并重新安装它们,我还检查了我一直在做的一个通过的应用程序,因为我刚刚开始,代码看起来相同,但似乎有效.
I tried deleting the modules and installing them again, I also checked on a passed application I've been doing and since I'm just starting out the code looks identical but that seems to work.
import { createStore, applyMiddleware } from "redux";
import promiseMiddleware from "redux-promise-middleware";
import userReducer from "./ducks/userReducer";
const middleware = applyMiddleware(promiseMiddleware());
const store = createStore(userReducer, middleware);
export default store;
import React, { Component } from "react";
import routes from "./routes";
import { Provider } from "react-redux";
import store from "./redux/store";
class App extends Component {
render() {
return (
<Provider store={store}>
<div className="App">{routes}</div>
</Provider>
);
}
}
export default App;
推荐答案
当你使用applyMiddleware
函数时,中间件不应作为函数调用.
When you use the function applyMiddleware
, the middlewares shouldn't be called as functions.
所以代替:
const middleware = applyMiddleware(promiseMiddleware());
做:
const middleware = applyMiddleware(promiseMiddleware);
参见 https://redux.js.org/api/applymiddleware#example-custom-logger-middleware 了解更多详情.
See https://redux.js.org/api/applymiddleware#example-custom-logger-middleware for more details.
这篇关于× TypeError:中间件不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!