reactjs - Appending React States to another State -
is there proper way append state state in react?
eg. state of have state of cat, dog , fish
this.state = { cat:true, dog:true, fish:true, all: cat, dog, fish }
this have currently:
var chosenanimals = {}; chosenanimals["cat"] = this.state.cat; chosenanimals["dog"] = this.state.dog; chosenanimals["fish"] = this.state.fish;
is there better way of doing this?
to push elements in state array need :
var chosenanimals = []; chosenanimals.push(this.state.cat, this.state.dog, this.state.fish);
if @ array.push (https://developer.mozilla.org/en-us/docs/web/javascript/reference/global_objects/array/push) returns length, in code provided chosenanimals contain 3 , not array looking for. calling push on array , not assigning (or itself) add items array.
Comments
Post a Comment