feat(async-await): add await in before fetch()
This commit is contained in:
parent
5a66948cb7
commit
93d9cd87a1
|
@ -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.');
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue