'Assign object to a variable before exporting as module default warning

    import axios from 'axios'

const baseUrl = 'http://localhost:3001/persons';

const getAll = () => {
    return axios.get(baseUrl);
}

const create = (newObject) => {
    return axios.post(baseUrl,newObject);
}

export default {
    getAll:getAll,
    create:create
}

Using axios to fetch data from server(in reactjs from json server), everything works fine but console shows this warning: Line 13:1: Assign object to a variable before exporting as module default. How to remove this warning??



Solution 1:[1]

You can also export the function individually to get rid of the warning:

import axios from 'axios';

const baseUrl = 'http://localhost:3001/persons';

export const getAll = () => { return axios.get(baseUrl); }
export const create = (newObject) => { return axios.post(baseUrl, newObject); }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 code