Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 ?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

...

const fileToImagePromises = liste.map(fileToImageURL);
console.log(fileToImagePromises) // return liste of Promise objet 
Promise.all(fileToImagePromises).then(setUploadedImages);

>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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading