-
-
Save gil00pita/19bebb36672a11de025a057088956f10 to your computer and use it in GitHub Desktop.
https://levelup.gitconnected.com/9-tricks-for-kickass-javascript-developers-in-2019-eb01dd3def2a Often times, it is necessary to fetch multiple datasets and do something for each of those or complete a task after all of the async calls have returned
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
import axios from 'axios' | |
let myData = [{id: 0}, {id: 1}, {id: 2}, {id: 3}] | |
async function fetchData(dataSet) { | |
for(entry of dataSet) { | |
const result = await axios.get(`https://ironhack-pokeapi.herokuapp.com/pokemon/${entry.id}`) | |
const newData = result.data | |
updateData(newData) | |
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