0

I am attempting to use a prop in a component without hard coding the name of the prop itself into the code since it can change dynamically.

I know react allows you to refer to affect state via square brackets in the code shown below. Is it possible to do something similar with this.props?

this.setState({[label]: ''});

This code would set whatever is stored in the label variable to ''. I am trying to use a prop in hopefully a similar way, but something like this.props.[label] does not work and puts out an unexpected character error. Any help would be appreciated.

W.Shields
  • 63
  • 1
  • 1
  • 10

0 Answers0