react-drag-drop-files icon indicating copy to clipboard operation
react-drag-drop-files copied to clipboard

Restart component original state

Open pcanas opened this issue 2 years ago • 7 comments

I'd like to, if I empty any set of files that have been dropped, the component message to restart to the original (i.e. from "Uploaded successfully. Upload another?" back to "Upload or drop a file right here")

How could I achieve this?

pcanas avatar Aug 26 '22 15:08 pcanas

Sam here. In my case, the handleChange function won't be called if someone uploads the same file again after an error occurred. I want to be able to reset the component state to null when an error occurs so handleChange gets called again when user uploads the same file.

samos123 avatar Sep 20 '22 20:09 samos123

Same issue here

Rajaotix avatar Sep 27 '22 12:09 Rajaotix

I have this exact same need

kejiweixun avatar Oct 12 '22 07:10 kejiweixun

+1

Riyaz-01 avatar Nov 10 '22 08:11 Riyaz-01

@samos123 Did you manage to solve this issue? I am struck at the same case. I need to reinitialize the fileuploader as I need to upload the same image again

ajithv11 avatar Nov 30 '22 14:11 ajithv11

I have managed to fix this by adding the property fileOrFiles as given below

const [fileAdded, setFileAdded] = useState(null);

<FileUploader 
fileOrFiles={fileAdded}
handleChange={ async (file)=>{
    // Process file like upload to server or make inner html

    setFileAdded(null);  // Resetting file this will allow to add same file

}}
/>

ajithv11 avatar Dec 01 '22 17:12 ajithv11

+1

stewones avatar Apr 27 '23 19:04 stewones