Resolve And Pass Multiple Values From A Then
fetchTrainer(trainerName)
.then(response => {
const trainerData = response.body;
return fetchPokemonFor({ trainerId: trainerData.id });
})
.then(response => {
// I want trainerData, but it is now out of scope...
});fetchTrainer(trainerName)
.then(response => {
const trainerData = response.body;
return Promise.all([
trainerData,
fetchPokemonFor({ trainerId: trainerData.id })
]);
})
.then(([trainerData, pokemonResponse]) => {
const pokemonData = pokemonResponse.body;
// do something with trainerData and pokemonData
});Last updated