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

Vis*_*wat 2 javascript reactjs redux react-redux

我收到此错误:

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});
Run Code Online (Sandbox Code Playgroud)

QoP*_*QoP 5

这是行不通的,因为您传递的是不带参数applyMiddleware的返回值。logger()

要修复它,您必须传递logger而不是logger()to applyMiddleware()

您可以在此处阅读有关自定义中间件的更多信息