AsTeR
AsTeR

Reputation: 7521

When calling createStore() I get: TypeError: middleware is not a function

Before flagging this has duplicates note that I have checked:

I am trying to integrate redux-thunk and use replace replaceReducer on my Redux store at the same time.

Basically, I have somewhere:

const {createStore, applyMiddleware} = require('redux');
const thunk = require('redux-thunk');
createStore(function() {return {}}, applyMiddleware(thunk));
// also tried
// createStore(function() {return {}}, {}, applyMiddleware(thunk));

And later:

store.replaceReducer(someCombinedReducer);

Right now, I am getting an error triggered through the createStore() line (so before any reducer replacement).

TypeError: middleware is not a function

Versions:

EDIT:

The stack trace is pointing to the applyMiddleware function exactly as in this question TypeError: middleware is not a function directly from the call I make.

Upvotes: 0

Views: 189

Answers (1)

AsTeR
AsTeR

Reputation: 7521

After a good night of sleep and some tweaking.

// thunk here is not undefined but and object
const thunk = require('redux-thunk');

Should be replaced by:

const thunk = require('redux-thunk').default;

Upvotes: 1

Related Questions