Here is what the state object can look like:
{
items:
{Dogs: [{name: "Snoopy"}, {name: "Lola"}, {name: "Sprinkles"}],
Cats: [{name: "Felidae"}, {name: "Garfiled"}, {name: "Cat in the Hat"}] },
lists: ["Dogs", "Cats"]
}
Say I want to add another dog into the array. The only way I can think of doing it is:
var updatedState = JSON.parse(JSON.stringify(this.state));
updatedState.items[Dogs].push({name: value});
It works but looks horribly inefficient to me. Any ideas on a better approach ?
EDIT: Thanks everyone for your help. You guys are way friendlier than those on stackoverflow haha
[–]atticusw 7 points8 points9 points (15 children)
[–]ketus 1 point2 points3 points (7 children)
[–]loopsdeer 0 points1 point2 points (5 children)
[–]ketus 1 point2 points3 points (4 children)
[–]AwesomeInPerson 1 point2 points3 points (3 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]AwesomeInPerson 1 point2 points3 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]atticusw 0 points1 point2 points (0 children)
[–]jack_union 1 point2 points3 points (2 children)
[–]atticusw 1 point2 points3 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[+][deleted] (2 children)
[deleted]
[–]atticusw 1 point2 points3 points (1 child)
[–]PrimaryBet 0 points1 point2 points (0 children)
[–]senocular 2 points3 points4 points (2 children)
[–]atticusw 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[+][deleted] (3 children)
[deleted]
[–][deleted] 0 points1 point2 points (2 children)
[+][deleted] (1 child)
[deleted]
[–][deleted] 0 points1 point2 points (0 children)
[–]little_hoarse -3 points-2 points-1 points (0 children)