I have been following this tutorial to create a React app with AWS Amplify.
https://aws.amazon.com/getting-started/hands-on/build-react-app-amplify-graphql/module-five/
At some point, the following snippet to retrieve the signed urls of images is present.
async function fetchNotes() {
const apiData = await API.graphql({ query: listNotes });
const notesFromAPI = apiData.data.listNotes.items;
await Promise.all(notesFromAPI.map(async note => {
if (note.image) {
const image = await Storage.get(note.image);
note.image = image;
}
return note;
}))
setNotes(apiData.data.listNotes.items);
}
My question is, how does the React app retrieve the urls? From my understanding the .map function retrieves a new Javascript array which is not stored in a variable when awaited in the await.Promise.all() part. The state in setNotes is updated with the const apiData, so the notes in apiData should not be able to change inplace.
I would appreciate if anyone can share some light on how the shared snippet works.