Answer the question
In order to leave comments, you need to log in
Use useRef or createRef to keep track of form fields?
There is a component with a form that, when submitted, simply sends the values of all fields to its parent. At the same time, the component itself does not change in any way when the data in the fields changes (except for the value inside these fields). I would like to know how best to read the field data when submitting. Since changing the field values does not bring any changes to the component, I consider the following 2 options:
1) hang createRef on each field. When the submit is triggered, read the values of the corresponding fields through these createRefs, enter these values into a common object and send them to the parent
2) create one common useRef object, and hang a handler on each field. Through the handler functions, the corresponding properties of the useRef object will be changed. When the submit is triggered, such an object is sent to the parent
I would like to know which option is better and why. Or use another way?
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question