Reputation: 51
I'm trying to concatenate the name of a state in set state method like this :
onCallMethod(name){ //name is a string
this.setState({myState + name : true});
}
But I found out that this is not working, I'm just beginning in React Native, how can I do that ??
Upvotes: 0
Views: 151
Reputation: 10025
Seems like you want to store multiple names in your state variable. But you're creating the names dynamically from the name string.
This is simply not possible. Try to manage an array/object of names in the state and update that array/object on each call.
state = {
names: {}
}
onCallMethod(name){
this.setState({names: {...this.state.names, [name]: true}});
}
Upvotes: 1