-2
rated 0 times
[
0]
[
2]
/ answers: 1 / hits: 20947
/ 7 Years ago, fri, december 1, 2017, 12:00:00
in a component I have:
constructor() {
super();
this.state = {
lists: [],
items: {}
};
}
handleAddList(s) {
var temp= this.state.lists.slice(0,this.state.lists.length);
temp.push(s);
this.setState({lists: temp},function(){
var toAdd={};
toAdd[s]=[];
How do I add toAdd to this.state.items ?
UPDATE,
I think I got it working with the following:
var ourLists = this.states.items;
ourlists[s] = [];
and then just setState.
I'm having trouble understanding the basic syntax of two lines:
toAdd[s] = []; is this just the way you specify a key value pair where the value is an array?
ahh, I got it.
More From » reactjs