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

onDrop fires twice

Open salmazov opened this issue 7 years ago • 6 comments

I add some files to uploader -> onDrop event fires twice "react-images-upload": "^1.2.3",

salmazov avatar Oct 24 '18 12:10 salmazov

Problem in source file index.js in 90 line:

this.setState({pictures: dataURLs, files: files}, () => { this.props.onChange(this.state.files, this.state.pictures); });

Callback call on parent method onChange. I don't undestand for what?

kibernetika avatar Nov 27 '18 11:11 kibernetika

Temporarily solution is making global variable Set type. Thoose in ever drop/add image adding in it file name and check before adding. If file name is exist in Set return from onDrop:

class AdminSlider extends Component {

check_images = new Set();

onDrop(pictureFiles) {
    if (pictureFiles.length > 0) {
        let index = pictureFiles.length - 1;
        if(this.check_images.has(pictureFiles[index])){ return }
        this.check_images.add(pictureFiles[index]);
       //...
    }
}

}

kibernetika avatar Nov 27 '18 13:11 kibernetika

Is it possible to get this published to npm? The current version seems to still have this bug.

jcrain avatar Dec 18 '18 23:12 jcrain

Same issue. I hope it gets published soon

Unicity-Pimentel avatar Dec 26 '18 05:12 Unicity-Pimentel

@JakeHartnell @kibernetika Thanks for hard work, has this issue been fixed? It still fires twice to me!

teknolojia avatar May 28 '19 14:05 teknolojia

https://github.com/JakeHartnell/react-images-upload/pull/95 is merged and this issue is still remains

Problem is in source file index.js in line 143 line:

removeImage(picture) { const removeIndex = this.state.pictures.findIndex(e => e === picture); const filteredPictures = this.state.pictures.filter((e, index) => index !== removeIndex); const filteredFiles = this.state.files.filter((e, index) => index !== removeIndex);

this.setState({pictures: filteredPictures, files: filteredFiles}, () => {
    this.props.onChange(this.state.files, this.state.pictures);
});

}

after state change Callback call on parent method onChange need to remove it (remove below line) this.props.onChange(this.state.files, this.state.pictures);

sw7x avatar Jun 07 '20 14:06 sw7x