为什么它说 'next' 没有在 redux 中间件代码中定义。是否弃用了下一个中间件方法?

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中中间件使用的next方法是被弃用了还是我用错了?

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