Home > Back-end >  How to get state's value when state name is in a variable and that variable?
How to get state's value when state name is in a variable and that variable?

Time:01-31

is there a way to use parameter to fetch state's value

I want to fetch a state's value, but the problem is that I am receiving state's name in a parameter.

Is there any way to do it directly? (Similar to what is represented in image)

CodePudding user response:

You have to use the variable in brackets like shown below:

function SampleFunc(name){
  const ddlValue = this.state[name]
}
  • Related