0

I am taking input from the user as a file using the below code:

render() {
  const handleFileChange: React.ChangeEventHandler<HTMLInputElement> = (e) => {
      e.persist();
      Array.from(e.currentTarget.files || []).forEach(file => {
        let modelname = file.name
        consle.log(modelname)
      });
    };
  return (
   <>
    <input accept=".csar,.yaml" type="file" name="filenameanddata" onChange={(e) => { 
     handleFileChange(e)}} /> 
    <label htmlFor="file">
     <Button className = {inputUploadButton} variant="primary" type="submit" onClick={e => e.stopPropagation()}>Upload
     </Button>
    </label>
  </>
 )
}

After taking input files display on UI and I am also given the option to delete them.

But after deleting I want to take the same file name from the user. In that input is not working properly.

How to do that any idea? or Is there any way to forcefully call onChange event if an event is not changed?

7
  • handleFileChange() Commented Oct 1, 2022 at 9:35
  • I am trying with handleFileChange() but its behavior is still same. I am not able to take same input again. @KonradLinkowski Commented Oct 1, 2022 at 10:17
  • So maybe the problem is not related to onChange. I guess that you want to use controlled input instead of uncontrolled one. Commented Oct 1, 2022 at 10:18
  • But if I am taking another input then it works. only when I am taking same input again then it will not work or onChange is not called Commented Oct 1, 2022 at 10:23
  • Becuase you didn't ever clear the value of that input Commented Oct 1, 2022 at 10:25

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.