React issue with file input element
Answered
raiyansarker posted this in #help-forum
I am having an issue in react and I don't know how to solve it properly. I have an input file element, and I have an onChange handler, when onChange handler fires, I show a modal, now the problem is, if user closes the modal, it can't be reopened because onChange won't fire if user selects the same file, it can't be even changed using ref as the ref current is read only, the only method that I came across is to make a new image element, but the component is already pretty hacky in many ways, and I don't want to introduce another hack, is there any other method that any of you know off?
Answered by raiyansarker
I found a way, I wrapped the input in a form component with a ref, when the modal closes, I have an effect where I remove all the states set by the modal and its components, revoke the object url and there I also resets the form using the ref. It is working perfectly fine!
1 Reply
I found a way, I wrapped the input in a form component with a ref, when the modal closes, I have an effect where I remove all the states set by the modal and its components, revoke the object url and there I also resets the form using the ref. It is working perfectly fine!
Answer