Skip to content

Instantly share code, notes, and snippets.

@AloofBuddha
Created August 2, 2023 19:11
Show Gist options
  • Save AloofBuddha/3d3059c0e65947be5c1709e798742454 to your computer and use it in GitHub Desktop.
Save AloofBuddha/3d3059c0e65947be5c1709e798742454 to your computer and use it in GitHub Desktop.
useEffect for video-store-pt-3
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