Javascript 为什么说';下一个';未在redux中间件代码中定义。中间件的下一种方法是否已弃用?
我得到这个错误:Javascript 为什么说';下一个';未在redux中间件代码中定义。中间件的下一种方法是否已弃用?,javascript,reactjs,redux,react-redux,Javascript,Reactjs,Redux,React Redux,我得到这个错误: index.js?dadc:6未捕获类型错误:next不是函数 ReactJS中中间件使用的下一个方法是否已被弃用,或者我是否使用了错误的方法 import { applyMiddleware, combineReducers , createStore } from 'redux'; const logger =(store) => (next) => (action) => { console.log('middle-ware called')
index.js?dadc:6未捕获类型错误: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});
这不起作用,因为您正在向
applyMiddleware
传递没有参数的logger()
的返回值
要修复它,您必须将logger
而不是logger()
传递到applyMiddleware()
您可以阅读有关自定义中间件的更多信息如果您使用
控制台会发生什么情况。在记录器中记录下一步的值
?