I try to do this:
getInitialState: function(){
return({
people: [] .... or people: [{id: "", key: ""}] or people: [[id: ][key: ]]
});
},
so I have an id and a key every person and I want to store it like this.
I try to do this:
getInitialState: function(){
return({
people: [] .... or people: [{id: "", key: ""}] or people: [[id: ][key: ]]
});
},
so I have an id and a key every person and I want to store it like this.
Looks like a syntax error. Try:
getInitialState () {
return {
people: []
};
}
This creates an empty array in your initial state. You can just populate your people array normally like so:
let p = this.state.people.slice();
p.push({id: "", key: ""});
this.setState({people: p});
The first line creates a copy of your people. You then push a new item to the temporary array. Finally you replace the old people state with the new one.
A one-liner way of doing this:
this.setState({people: this.state.people.concat([{id: "", key: ""}])});