react-drag-drop-files
react-drag-drop-files copied to clipboard
Restart component original state
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?
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.
Same issue here
I have this exact same need
+1
@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
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
}}
/>
+1