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

Imageuploader not resetting after images are uploaded #187

Open
prakashnov07 opened this issue Sep 1, 2020 · 2 comments
Open

Imageuploader not resetting after images are uploaded #187

prakashnov07 opened this issue Sep 1, 2020 · 2 comments

Comments

@prakashnov07
Copy link

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.

@niniks
Copy link

niniks commented Nov 26, 2020

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 = [];

@Floridus
Copy link

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 = [];

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

3 participants