feat(async-await): add await in before fetch()

This commit is contained in:
dancingCycle 2023-12-04 14:40:02 +01:00
parent 5a66948cb7
commit 93d9cd87a1
1 changed files with 3 additions and 3 deletions

View File

@ -1,9 +1,9 @@
async function fetchDataFromApi() {
console.log('fetchDataFromApi() start...');
fetch('https://v2.jokeapi.dev/joke/Programming?type=single')
.then(res => res.json())
.then(json => console.log(json.joke));
const res = await fetch('https://v2.jokeapi.dev/joke/Programming?type=single');
const json = await res.json();
console.log(json.joke);
console.log('fetchDataFromApi() done.');
};