Created
December 25, 2018 16:46
-
-
Save gisderdube/ba2b4b72d50f82c88afa1cf540caefa8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import axios from 'axios' | |
let myData = [{id: 0}, {id: 1}, {id: 2}, {id: 3}] | |
async function fetchData(dataSet) { | |
const pokemonPromises = dataSet.map(entry => { | |
return axios.get(`https://ironhack-pokeapi.herokuapp.com/pokemon/${entry.id}`) | |
}) | |
const results = await Promise.all(pokemonPromises) | |
results.forEach(result => { | |
updateData(result.data) | |
}) | |
console.log(myData) | |
} | |
function updateData(newData) { | |
myData = myData.map(el => { | |
if(el.id === newData.id) return newData | |
return el | |
}) | |
} | |
fetchData(myData) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment