Ok, so I am trying to up-skill my self with ES6 JS, but I am using the Axios plugin to get data from an API.
However I can not seem to access the data outside of the then
call from Axios,
let testData = {};
axios.get(URL, {headers: {Authorization: `Bearer ${TOKEN-HERE}`}}).then((res) => {
testData = res.data;
});
console.log(testData); <- this is still empty?
So as far as I understand, the arrow function was meant to keep the context the same? so I dont have to do anything like let self = this
to assign data from Axios into my data var?
But if I console.log(testData)
within the Axios get call, it returns my data?
So what am I doing wrong? And how do I get data out of that Axios call?
Please help?