反应错误 - 在导出为模块之前将箭头函数分配给变量,然后
React Error - Assign arrow function to a variable before exporting as module and
我正在尝试通过 github 连接在 Azure App Service 上部署以下源,但以下错误正在停止构建,但在我的本地 linux 框中它工作正常,没有任何警告。
错误:
src/context/alert/alertReducer.js
第 3:1 行:在导出为模块默认 import/no-anonymous-default-export
之前,将箭头函数分配给变量
src/context/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 engines。
有些可能不允许您导出未命名的函数。试试这个。
const reducer (state, action) => {
switch (action.type) {
case SET_ALERT:
return action.payload;
case REMOVE_ALERT:
return null;
default:
return state;
}
};
export default reducer
我正在尝试通过 github 连接在 Azure App Service 上部署以下源,但以下错误正在停止构建,但在我的本地 linux 框中它工作正常,没有任何警告。
错误: src/context/alert/alertReducer.js 第 3:1 行:在导出为模块默认 import/no-anonymous-default-export
之前,将箭头函数分配给变量src/context/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 engines。 有些可能不允许您导出未命名的函数。试试这个。
const reducer (state, action) => {
switch (action.type) {
case SET_ALERT:
return action.payload;
case REMOVE_ALERT:
return null;
default:
return state;
}
};
export default reducer