Is there a way to generate the state values from a form automatically. Say I have a form with 100000 input all have random names so not like name_1 name_2 or so. Names are not automatically generated or anything.(Which i do not have but just curious).
Can I generate the state values automatically for each input field.
We can have one function to handle input and use e.target.name
and e.target.value
to set the state. But can we initialize the state with these names to empty values.
You create the state in constructor and so constructors would not have an idea of the fields yet.
Or do we leave the state empty initially and we add the new field to state when onChange happens. We check if the name is in the state if so update if not deep copy the old state and add the new name/value and set it as the new state ?
Thanks.
I am just after a better way to do this.