我有一个简单的应用程序.我有一个上传读取到一个钩子多个图像.
useEffect(() => {
const CallMe = async () => {
// files contains 2 images
if (files.length > 0) {
return Promise.all(
files.map(async (file, idx) => {
return new Promise(async (resolve, reject) => {
try {
const image = await resizeFile(file[idx]);
console.log(image);
resolve(image);
} catch (error) {
reject(error);
}
});
})
);
}
};
CallMe().then((res) => {
setThumbnails([...thumbnails, res]);
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [files]);
{thumbnails.length &&
thumbnails?.map((img, idx) => {
if (img)
return (
//ONLY ONCE IS SHOWN
<img
key={idx}
src={img}
alt="soso"
height={100}
width={100}
></img>
);
})}