Created
August 2, 2023 19:11
-
-
Save AloofBuddha/3d3059c0e65947be5c1709e798742454 to your computer and use it in GitHub Desktop.
useEffect for video-store-pt-3
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
useEffect(() => { | |
async function omdbAPIRequest() { | |
const requests = inventory.map((inventoryItem) => { | |
return axios.get( | |
`http://www.omdbapi.com/?i=${inventoryItem.id}&apikey=7f539340` | |
); | |
}); | |
const responses = await Promise.allSettled(requests); | |
const responseDatas = responses.map((response) => response.value.data); | |
const updatedInventory = responseDatas.map((responseData) => { | |
const associatedInventoryItem = getInvetoryItemById( | |
responseData.imdbID | |
); | |
responseData.id = associatedInventoryItem.id; | |
responseData.copiesAvailable = associatedInventoryItem.copiesAvailable; | |
responseData.totalAvailable = associatedInventoryItem.totalAvailable; | |
return responseData; | |
}); | |
setInventory(updatedInventory); | |
} | |
omdbAPIRequest(); | |
}, []); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment