Last active
August 25, 2020 17:46
-
-
Save psynewave/42ca195b89999b6dd0564bb8af7650cf to your computer and use it in GitHub Desktop.
Promise All Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const apiURL = "https://pokeapi.co/api/v2/type/1"; | |
const pokemonFetch = async () => { | |
const initial = await fetch(apiURL); | |
const initialJson = await initial.json(); | |
const detailsData = initialJson.pokemon.map(async i => { | |
const preFetchData = await fetch(i.pokemon.url); | |
return preFetchData.json(); | |
}) | |
const payload = (await Promise.all(detailsData)).map(data => ({ | |
name: data.name, | |
image: data.sprites['front_default'] | |
})) | |
return payload; | |
} | |
pokemonFetch().then(resp => { | |
console.log(resp); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment