redux - 当调用 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
版本:
- 还原:4.0.1
- redux-thunk:2.3.0
编辑:
堆栈跟踪指向的函数与这个问题TypeError: middleware is not a function directly from the call I make.applyMiddleware
完全相同。
解决方案
经过一夜好眠和一些调整。
// thunk here is not undefined but and object
const thunk = require('redux-thunk');
应替换为:
const thunk = require('redux-thunk').default;
推荐阅读
- math - Lua:如何计算50到500之间的随机数,平均结果为100?
- android - CardView 中突出显示的文本没有颜色
- android - 类型 androidx.viewpager.widget.PagerAdapter 被定义多次
- javascript - 在 React 17 中使用设置样式组件背景图像的道具
- javascript - 如何检查 HTMLCollection 中的所有元素是否包含某个属性的某个值?
- laravel - 如何在 laravel 运行时设置或更改全局变量值
- node.js - 当 npm audit fix / update / shrinkwrap 手动更改不起作用时,如何更新 node-sass 的嵌套包 ansi-regex?
- python - RuntimeWarning: 在 cosh -- Python 中遇到溢出。这是什么意思?
- angular - 在嵌套事件处理程序中传递参数
- php - 来自 php Curl 的 FCM 请求永远存在