Skip to content

Instantly share code, notes, and snippets.

@psynewave
Last active August 25, 2020 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save psynewave/42ca195b89999b6dd0564bb8af7650cf to your computer and use it in GitHub Desktop.
Save psynewave/42ca195b89999b6dd0564bb8af7650cf to your computer and use it in GitHub Desktop.
Promise All Example
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