Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unexpected default export of anonymous function import/no-anonymous-default-export

How to avoid this kind of warning?
It gives warning like below.

 Unexpected default export of anonymous function import/no-anonymous-default-exp 

This is the function which gives warning.

import { FETCH_USER } from '../actions/types';

export default function(state = null, action){
    switch(action.type) {
        case FETCH_USER:
            return action.payload || false ;
        default:
            return state;
    }
}
like image 778
Abdol Karim Avatar asked Dec 03 '20 20:12

Abdol Karim


2 Answers

To avoid this kind of warning, now I am no longer using anonymous functions. So, try this...

export default function foo(state = null, action){
    switch(action.type) {
        case FETCH_USER:
            return action.payload || false ;
        default:
            return state;
    }
}
like image 81
meirellesMS Avatar answered Sep 20 '22 18:09

meirellesMS


You are getting the error because in this line of code, you have not provided the function name:

export default function(state = null, action){

The code will still work, however to get rid of the warning provide a function name like so:

export default function functionName(state = null, action){
like image 21
Shasa Avatar answered Sep 23 '22 18:09

Shasa