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

Clear Images on Submit

Open MusabAkram opened this issue 6 years ago • 6 comments

I want to remove all the selected images that are being previewed after the images are uploaded successfully.

MusabAkram avatar May 07 '19 10:05 MusabAkram

The best solution I found is to pass a new key prop to it, which will get the component reloaded.

andobotar avatar May 08 '19 20:05 andobotar

@andobotar Please show some example regarding how to pass props. Thanks

RobertStuff avatar Oct 01 '19 06:10 RobertStuff

@RobertStuff

I use this in a bigger form component, where I keep a number in state for the 'key': const [ImageUploaderKey, setImageUploaderKey] = useState(0); And when the form is submitted successfully, I increment this number: setImageUploaderKey(ImageUploaderKey + 1); Then I pass this key to the component: <ImageUploader key={ImageUploaderKey} ... />

Hope this helps.

andobotar avatar Oct 01 '19 11:10 andobotar

@RobertStuff

I use this in a bigger form component, where I keep a number in state for the 'key': const [ImageUploaderKey, setImageUploaderKey] = useState(0); And when the form is submitted successfully, I increment this number: setImageUploaderKey(ImageUploaderKey + 1); Then I pass this key to the component: <ImageUploader key={ImageUploaderKey} ... />

Hope this helps.

thank I will try it later...

RobertStuff avatar Oct 01 '19 23:10 RobertStuff

@andobotar

It works thanks...

RobertStuff avatar Oct 02 '19 02:10 RobertStuff

@andobotar One more thing. Have you encounter when you have a defaultImages. It always shows even if you added a new image?

RobertStuff avatar Oct 02 '19 03:10 RobertStuff