7

I already know how to setState with a dynamic key name but how do I set a value as the state with a dynamic key?

Example

function thing(key) {
 let stuff = this.state.key;

 //Do stuff
}
Aaron
  • 1,677
  • 3
  • 13
  • 17

1 Answers1

28

Didn't even think of think of this as first but all I did was

function thing(key) {
 let stuff = this.state[key];

 //Do stuff
}

and it worked!

Aaron
  • 1,677
  • 3
  • 13
  • 17