React错误-在导出为模块和之前将箭头函数分配给变量



我试图通过github连接在Azure应用服务上部署以下源代码,但以下错误正在停止构建,但在我的本地linux盒子中其工作正常,没有任何警告。

错误:src/背景/警告/alertReducer.js第3:1行:在导出之前将箭头函数赋值给一个变量作为模块默认值import/no-anonymous-default-export

src/背景/github/githubReducer.js第10:1行:在导出之前将箭头函数赋值给一个变量作为模块默认值import/no-anonymous-default-export

alertReducer.js

import { SET_ALERT, REMOVE_ALERT } from "../types";

export default (state, action) => {
switch (action.type) {
case SET_ALERT:
return action.payload;
case REMOVE_ALERT:
return null;
default:
return state;
}
};

githubReducer.js

// Importing types
import {
SEARCH_USERS,
SET_LOADING,
CLEAR_USERS,
GET_USER,
GET_REPOS,
} from "../types";
export default (state, action) => {
switch (action.type) {
case GET_USER:
return {
...state,
user: action.payload,
loading: false,
};
case GET_REPOS:
return {
...state,
repos: action.payload,
loading: false,
};
case SEARCH_USERS:
return {
...state,
users: action.payload,
loading: false,
};
case CLEAR_USERS:
return {
...state,
users: [],
loading: false,
};
case SET_LOADING:
return {
...state,
loading: true,
};
default:
return state;
}
};

不同的环境使用不同的JS引擎。有些可能不允许导出未命名的函数。试试这个。

const reducer (state, action) => {
switch (action.type) {
case SET_ALERT:
return action.payload;
case REMOVE_ALERT:
return null;
default:
return state;
}
};
export default reducer

最新更新