×TypeError:中间件不是功能

时间:2019-02-13 06:43:54

标签: redux react-redux

image of the ERROR 好的,所以我正在开始一个新项目,这是我第一次发生这种情况,我不断收到错误提示× TypeError:中间件不是我检查过依赖项的函数,一切似乎都遍历了我的代码,似乎没有错,请帮忙

我尝试删除模块并再次安装它们,我还检查了我一直在通过的应用程序,由于我刚入门时代码看起来相同,但这似乎可行。

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;

1 个答案:

答案 0 :(得分:1)

使用功能applyMiddleware时,不应将中间件称为功能。

所以代替:

const middleware = applyMiddleware(promiseMiddleware());

这样做:

const middleware = applyMiddleware(promiseMiddleware);

有关更多详细信息,请参见https://redux.js.org/api/applymiddleware#example-custom-logger-middleware