Skip to content Skip to sidebar Skip to footer

Refactor Promise And Promise.all With Async Await Of Es2017

I have a working version of a photo upload handler but I would want to see how it work with async await. Before anything below is my working code using promise. onChangePhotos = (e

Solution 1:

Not sure what the error is suppose to mean, because of lack of information, but your promises array has no promises, because you already use await:

I suggest changing this:

let promises = []
for(const file of files){
  const uploadPhotoPromise = await UploadApi.singlePhoto(file)
  promises.push(uploadPhotoPromise)
}

to:

const promises = [];

for(const file of files){
  promises.push(UploadApi.singlePhoto(file))
}

Post a Comment for "Refactor Promise And Promise.all With Async Await Of Es2017"