reducer.js 报错 Assign arrow function to a variable before exporting as module default import/no-anonymous-default-export
export default (state = initState, action) => {
console.log(12, action);
switch (action.type) {
case 'INCREMENT': //增加 加一
return state + action.data;
case 'DECREMENT':
return state - action.data;
default:
return state;
}
}
这样写会报错:Assign arrow function to a variable before exporting as module default import/no-anonymous-default-export
原因: 可能是你的编程工具安装了ESLint,所以这样写会显示错误,
解决方法:
把纯函数赋值给一个变量 const, 然后到处变量就可以了
const calculate = (state = initState, action) => {
console.log(12, action);
switch (action.type) {
case 'INCREMENT': //增加 加一
return state + action.data;
case 'DECREMENT':
return state - action.data;
default:
return state;
}
}
export default calculate;