react-images-upload icon indicating copy to clipboard operation
react-images-upload copied to clipboard

Remove wrong images when uploader has defaultImages prop

Open nhidh99 opened this issue 5 years ago • 0 comments

After I added some new images to the uploader that has defaultImages prop, then I removed the first default image, it works well with the URLs, but the first uploaded image file in the file list also was deleted.

It turns out that the file list length and the URL list length do not match in this case, so I decided to clone your component and update the onDropFile(e) function by replacing push URL and file by unshift them.

Promise.all(allFilePromises).then((newFilesData) => {
    const dataURLs = singleImage ? [] : this.state.pictures.slice();
    const files = singleImage ? [] : this.state.files.slice();

    newFilesData.forEach((newFileData) => {
        dataURLs.unshift(newFileData.dataURL);    // replace push
        files.unshift(newFileData.file);          // replace push
    });

    this.setState({ pictures: dataURLs, files: files });
});

The other way is updating the removeImage(picture) to remove the correct element, but I cannot find the solution.

If there is something wrong with my approach, please let me know.

nhidh99 avatar Jul 23 '20 17:07 nhidh99