【问题标题】:When calling createStore() I get: TypeError: middleware is not a function当调用 createStore() 我得到: TypeError: middleware is not a function
【发布时间】:2019-11-13 12:18:16
【问题描述】:

在标记此内容之前,请注意我已检查过的重复项:

我正在尝试在我的 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

版本:

  • redux:4.0.1
  • redux-thunk:2.3.0

编辑:

堆栈跟踪指向applyMiddleware 函数,正如我直接从我进行的调用中的问题TypeError: middleware is not a function 一样。

【问题讨论】:

  • 您能否详细说明该错误的来源?这是实际的运行时错误吗?打字稿错误?有堆栈跟踪吗?
  • @markerikson 已编辑

标签: redux redux-thunk redux-middleware


【解决方案1】:

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

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

应替换为:

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

【讨论】:

    猜你喜欢
    • 2020-11-16
    • 1970-01-01
    • 2020-01-20
    • 2019-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多