how to use Promise reactjs

first experience with react,
the script return a list of Promise.

enter image description here

how i can update uploadedImages ?

const [uploadedImages, setUploadedImages] = useState<CustomImage[]>([]);


const fileToImagePromises =;
console.log(fileToImagePromises) // return liste of Promise objet 

>Solution :

It’s not specific to react, it is JavaScript,

Using the callback as

Promise.all(fileToImagePromises).then(data => setUploadedImages(data))

But the point would be where you are setting the state, if you do it unconditionally in function component body it would infinitely re-render

Leave a Reply