I have an upload component that uploads an image to firebase. When that was successful I want to empty the file input and rerender the component however it seems I can't reset the state in order to trigger a rerender. I already read, that setting state to null doesn't work so I tried a dummy object but console log always gives me the previous file name.
I would be thankful for a rerender fix or for some general advice how to handle this better.
const onFileChange = (e) => {
setFile(e.target.files[0]);
};
const onUpload = async () => {
if (file) {
// do something
setFile({ file: "none" });
console.log(file.name);
}
};
return (
<>
<input type="file" onChange={onFileChange} />
<button onClick={onUpload}>Upload image</button>
</>
);