首页 > 解决方案 > 当调用 createStore() 我得到: TypeError: middleware is not a function

问题描述

在标记这有重复之前,请注意我已经检查过:

我正在尝试同时在我的 Redux 商店上集成redux-thunk和使用替换。replaceReducer

基本上,我有一个地方:

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

然后:

store.replaceReducer(someCombinedReducer);

现在,我通过createStore()线路触发了一个错误(所以在更换任何减速器之前)。

TypeError: middleware is not a function

版本:

编辑:

堆栈跟踪指向的函数与这个问题TypeError: middleware is not a function directly from the call I make.applyMiddleware完全相同。

标签: reduxredux-thunkredux-middleware

解决方案


经过一夜好眠和一些调整。

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

应替换为:

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

推荐阅读