Skip to content
This repository has been archived by the owner on Jun 5, 2022. It is now read-only.

Remove wrong images when uploader has defaultImages prop #179

Open
nhidh99 opened this issue Jul 23, 2020 · 0 comments
Open

Remove wrong images when uploader has defaultImages prop #179

nhidh99 opened this issue Jul 23, 2020 · 0 comments

Comments

@nhidh99
Copy link

nhidh99 commented Jul 23, 2020

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant