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)
这是行不通的,因为您传递的是不带参数applyMiddleware
的返回值。logger()
要修复它,您必须传递logger
而不是logger()
to applyMiddleware()
。