Reputation: 61
I'd like to create a new object. The key and value of the new object are the inputs from TextInput
. Below please see my code. Obviously when I hit submit, the new object will always take the string 'key' as its key and not the value that I input. How do I fix it? Thank you.
state = {
list: [{key1:1},{key2:2}],
key:'',
value:0,
}
_onSubmit = () =>{
let {list,key,value} = this.state;
let myList = [...list];
let newProp = {};
newProp.key = value;
myList.push(newProp);
this.setState({list: myList});
}
Upvotes: 0
Views: 48