How to resolve the promise that return from fetch in a async/await fn? Is this even possible?
e.g
async function getData() {
const data = await fetch([url]);
const parsedData = await data.json() // or data.text()
return parsedData;
}
const data = getData(); // console.log(data) ---> shows unresolved promise object
~~~~~~~~~~~~~~~~~~
//Works with .then() chain return
const data = getData().then(res => res);
// Second example except using a middle layer async/await function:
async function getData() {
const data = await fetch([url]);
const parsedData = await data.json() // or data.text()
return parsedData;
}
async function processData() {
const data = await getData();
}
const da = processData();
Is there a way to do it without the .then()
or two async/await
functions as shown in the first example?