I just came across this after trying to perform form validation before opening the modal layout of the validation using React 14.
I would like to point out that you are not actually accessing the DOM element with links. You simply access the React Component object. Shown here:
![enter image description here](https://fooobar.com/undefined)
The top calls ref.ticketForm
, the bottom shows document.getElementById('ticketform')
.
The reason I needed to do this was as follows:
<Button color="success" size="lg" type="button" onClick={(e) => { const ticketForm = document.getElementById('ticketForm'); const isValid = ticketForm.reportValidity(); if (!isValid) e.stopPropagation(); }}>Buy Tickets</Button>
reportValidity()
is a DOM element method: https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/reportValidity
Addressing this problem, this person showed that this method is used on a reference object, which, of course, is not correct: https://github.com/azmenak/react-stripe-checkout/issues/121#issuecomment-431635855
Hopefully this makes it clear that DOM elements are not explicitly equal React Components. If you need to manipulate the DOM in any way, first do it in a responsive way. This is an extreme case where I would rather rely on form validation for a dynamic form rather than on manual validation.
source share