I want to get a value from state, but the problem is that I’m receiving the state's key from 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]
}
Also it’s better to use const instead of let when you know you don’t want to change the variable’s value in it’s scope.