KarimMokhtar / react-drag-drop-files

Light and simple Reactjs drag and drop files library to use with very flexible options to change, so you put whatever the design you want for your drop-area. Users can drag and drop or even select the file anywhere in the window.
MIT License
245 stars 86 forks source link

Restart component original state #79

Open pcanas opened 2 years ago

pcanas commented 2 years ago

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?

samos123 commented 2 years ago

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.

Rajaotix commented 1 year ago

Same issue here

kejiweixun commented 1 year ago

I have this exact same need

Riyaz-01 commented 1 year ago

+1

ajithv11 commented 1 year ago

@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 commented 1 year ago

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

}}
/>
stewones commented 1 year ago

+1