I
I
Ibishka2020-09-03 15:10:02
React
Ibishka, 2020-09-03 15:10:02

How to access React js elements?

The bottom line is that I have a form and there are several inputs in it. I need to remove disabled from them on submit when 1 element with ref is all good and when there are several elements what to use querySelectorAll?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Arthur, 2020-09-03
@Ibishka

direct access to the DOM is contrary to the concept of react
, it is better if you make a state and draw the form content based on it

const [submited, setSubmited] = useState(false)
const handleSubmitForm = () => {
  setSubmited(true)
}
...
<form onSubmit={handleSubmitForm}>
  <input disabled={!submited} />
  <input disabled={!submited} />
</form>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question