I'm trying to assign the axios response data to a variable I've defined in global scope. In console i get undefined if I try to log the variable after a value it's assigned in then() callback. How I can fix and avoid this error in future?
let eas;
const fetchData = () => {
axios({
method: "GET",
baseURL: "https://example-api.com",
responseType: "json"
}).then( (response) => {
eas = response.data;
});
console.log(eas); // this will result in undefined
}
NB: I'm inside a promise callback. I've readed the suggested question but I don't want to create a function only to assign the response value, it will be overkill for my app.