0

How to setState with a variable like the following:

this.handler = (field) => {

this.setState({field:'value'})

}

Please help I am having trouble doing it.

1 Answers1

1

this will solve your issue

this.handler = (field) => {
  this.setState(
     { [field] :'value'}
  );
}
Sunil Kumar
  • 420
  • 4
  • 13