I have a react component which renders a <input type="file">
dom to allow user select images from browser. I found that its onChange method not called when I select the same file. After some searching, someone suggests using this.value=null
or return false
at the end of the onChange method but I have tried it doesn't work.
Below is my code:
<input id="upload" ref="upload" type="file" accept="image/*" onChange={(event)=> { this.readFile(event) }}/>
Below is what I tried:
<input id="upload" ref="upload" type="file" accept="image/*" onChange={(event)=> { this.readFile(event) return false }}/>
Another one is:
<input id="upload" ref="upload" type="file" accept="image/*" onChange={(event)=> { this.readFile(event) this.value=null }}/>
I believe above solutions work for jquery but I don't know how to let it work in reactjs.
Select a File (user input): To enable the user to pick a file, the first step is to add the tag to our App component. This tag should have the type attribute set as “file”.
Dup of this thread
<input id="upload" ref="upload" type="file" accept="image/*" onChange={(event)=> { this.readFile(event) }} onClick={(event)=> { event.target.value = null }} />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With