I've written a bit of code that looks like this:
async function fetchData() {
const json = await fetch(ENDPOINT + key.key).then(data => data.json());
//Do something with the data
}
It's pretty clear and straight forward what I'm doing here.
I'm just wondering if it's normal to combine both the older Promise style, and the new async/await style like this.
If I wasn't to use .then
then I'd be something like this:
async function fetchData() {
const data = await fetch(ENDPOINT + key.key);
const json = await data.json();
//do something with the data
}
Unless I'm missing something here? I guess the question is - is the purpose of async/await to stop using promises completely - or what?
is the purpose of async/await to stop using promises completely?
-- No, async functions return promises. See javascript.info/async-await