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

onDrop fires twice #88

Open
salmazov opened this issue Oct 24, 2018 · 6 comments
Open

onDrop fires twice #88

salmazov opened this issue Oct 24, 2018 · 6 comments

Comments

@salmazov
Copy link

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

@kibernetika
Copy link
Contributor

kibernetika commented Nov 27, 2018

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
Copy link
Contributor

kibernetika commented Nov 27, 2018

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]);
       //...
    }
}

}

himelnagrana added a commit to himelnagrana/react-images-upload that referenced this issue Nov 30, 2018
replicating the pull request for (Issue JakeHartnell#88 fixed: onDrop fires twice) in the main repo. JakeHartnell#95
himelnagrana added a commit to himelnagrana/react-images-upload that referenced this issue Nov 30, 2018
replicating the pull request for (Issue JakeHartnell#88 fixed: onDrop fires twice) in the main repo. JakeHartnell#95
@jcrain
Copy link

jcrain commented Dec 18, 2018

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

@Unicity-Pimentel
Copy link

Same issue. I hope it gets published soon

JakeHartnell added a commit that referenced this issue Dec 29, 2018
Issue #88 fixed: onDrop fires twice
@teknolojia
Copy link

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

@sw7x
Copy link

sw7x commented Jun 7, 2020

#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);

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

6 participants