I have a form in react containing multiple text boxes. I am trying to fetch the values of all text boxes on click of a button. For that I am using an array of states. Here´s my state which is an array of objects:
const [myState, setMyState] = useState([{
stringValue: {
name: "",
value: ""
},
}])
And here´s my text field:
<TextField
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
setMyState([...myState, {
stringValue: {
name: displayName,
value: e.target.Value
}
},])}
/>
On button click I want to get the values of all textboxes but since I am using a state array, my myState array looks something like this :
h
he
hel
hell
hello
If I don´t use state array, I end up overwriting the state. How can I get I save the full string "hello" to myState instead of all the individual characters?