我收到此错误:
index.js?dadc:6Uncaught TypeError: next 不是函数
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()
。
您可以阅读有关自定义中间件的更多信息 here
关于javascript - 为什么它说 'next' is not Defined in redux middleware code.中间件的下一个方法是否已弃用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39314057/