Christian Gonzalez
Christian Gonzalez

Reputation: 107

× TypeError: middleware is not a function

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;

Upvotes: 2

Views: 3192

Answers (1)

Matt Stobbs
Matt Stobbs

Reputation: 639

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.

Upvotes: 3

Related Questions