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

Imageuploader not resetting after images are uploaded

Open prakashnov07 opened this issue 5 years ago • 2 comments

When images are uploaded, i am sending back empty array to set selected images to [], but even as the selected images have become [] they are showing in the preview.

prakashnov07 avatar Sep 01 '20 06:09 prakashnov07

For the ones searching for a quick fix..

Add an ref to your component <ImageUploader ref={this.myRef}

In your constructor: this.myRef = React.createRef();

In the function which will be called after success upload: this.setState({pictures: []}); this.myRef.current.state.pictures = [];

niniks avatar Nov 26 '20 08:11 niniks

So I was able to find a workaround. The reference has its own state that can be accessed.

const imageUploadRef = useRef(null);

<ImageUploader ref={imageUploadRef} ... />

Reset all uploads after onChange call

imageUploadRef.current.state.pictures = [];
imageUploadRef.current.state.files = [];

Floridus avatar Jan 14 '21 11:01 Floridus