This is how I access the result from a fetch call:
let data;
fetch(someUri)
.then((response) => response.json())
.then(_data => {
data = _data;
})
.catch(error => {
console.error(error);
});
Is it also possible to access the result from the fetch function itself, like this:
let data = fetch(someUri)
.then((response) => response.json())
.then(data => {
// do some stuff
return data;
})
.catch(error => {
return error;
});
So data
will be either the JSON data or the error. I see in my Chrome console that the result is in the variable, but I don't know how to access it because it's wrapped with other information.