为什么上面写着'next'在redux中间件代码中没有定义.中间件的next方法是否已弃用
Why does it says that 'next' is not defined in redux middleware code. Is next method of middleware deprecated?
我得到这个错误:
index.js?dadc:6Uncaught TypeError: next is not a function
是下一个方法使用的中间件在ReactJS弃用或我使用它不正确?
import { applyMiddleware, combineReducers , createStore } from 'redux';
const logger =(store) => (next) => (action) => {
console.log('middle-ware called');
next(action);
}
const reducer=(state ,action)=>{
if(action.type=='INC'){
console.log('a-----------------',action);
return state+action.payload;
}
else
return state; };
const store=createStore(reducer ,1 ,applyMiddleware(logger()));
store.subscribe(()=>{
console.log('store changed',store.getState()) });
store.dispatch({type :'INC' ,payload : 10}); store.dispatch({type :'INC' ,payload : 10});
这不起作用,因为您将logger()
的返回值传递给applyMiddleware
而没有参数。
要修复它,您必须传递logger
而不是logger()
到applyMiddleware()
。
您可以在这里阅读更多关于自定义中间件的信息
在我的例子中,我试图传递一个增强器作为中间件。将增强器从middleware
移动到enhancers
修复了这个问题。https://redux-toolkit.js.org/api/configureStore#enhancers
相关文章:
- 为什么grunt contrib connect的中间件选项的第三个参数是未定义的
- 什么'在Express中路由时,应用程序级中间件和路由器级中间件之间的区别是什么
- Redux中间件在next()之前更改状态
- 快速的套接字 io 实例/中间件
- 如何使用Express'正确加载图像;s的静态中间件
- 如何在快递中制作中间件的动态链.js
- 在 Redux 中,在商店中应用中间件未正确称为化简器
- 意思是.JS中间件中的猫鼬填充不起作用
- "Cookies的这个实例“;在nodejs cookie中间件的源代码中
- Expressjs:如何跨路由共享路由中间件
- 如何在Keystone.js项目中使用Express.js中间件
- Express.js恶意路径中间件错误403
- 编写中间件'它不知道它在堆栈上的位置
- Router.use()需要中间件函数,但得到了一个未定义的函数
- webpack-dev中间件,如何在HMR失败时自动卸载
- 谁在Express中间件中提供next()函数
- 我是否需要在我的中间件中使用“next”或“store.dispatch”
- Express.js:从路由处理程序中调用next(error)会调用全局错误处理中间件吗?
- 为什么上面写着'next'在redux中间件代码中没有定义.中间件的next方法是否已弃用
- 测试返回next() / next("route")的快速中间件