Assign Object to a Variable Before Exporting as Module Default Warning

Assign Object to a Variable Before Exporting as Module Default Warning
    import axios from 'axios'

const baseUrl = '

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??

2

3 Answers

You need to assign the object to a variable before exporting it as default.

const exportedObject = {
     getAll,
     create,
};

export default exportedObject;

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

import axios from 'axios';

const baseUrl = '

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

You can remove this warning by just adding the comment "// eslint-disable-next-line" before export.

import axios from 'axios'

const baseUrl = '

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

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

// eslint-disable-next-line
export default {
    getAll:getAll,
    create:create
}
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

James H. Sterling
Author

James H. Sterling

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.