React Error - Assign arrow function to a variable before exporting as module and

Viewed 1817

I am trying to deploy the following source on Azure App Service via github connection but following errors are stopping the build but in my local linux box its working fine without any warning.

Error: src/context/alert/alertReducer.js Line 3:1: Assign arrow function to a variable before exporting as module default import/no-anonymous-default-export

src/context/github/githubReducer.js Line 10:1: Assign arrow function to a variable before exporting as module default 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;
  }
};
1 Answers

Different environments use different JS engines. Some might not allow you to export unnamed functions. Try this.

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