× TypeError: middleware is not a function

我与影子孤独终老i 提交于 2019-12-25 00:08:21

问题


image of the ERROR OK 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;


回答1:


When you use the function applyMiddleware, the middlewares shouldn't be called as functions.

So instead of:

const middleware = applyMiddleware(promiseMiddleware());

do:

const middleware = applyMiddleware(promiseMiddleware);

See https://redux.js.org/api/applymiddleware#example-custom-logger-middleware for more details.



来源:https://stackoverflow.com/questions/54664110/%c3%97-typeerror-middleware-is-not-a-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!