How to setState with a variable like the following:
this.handler = (field) => {
this.setState({field:'value'})
}
Please help I am having trouble doing it.
How to setState with a variable like the following:
this.handler = (field) => {
this.setState({field:'value'})
}
Please help I am having trouble doing it.
this will solve your issue
this.handler = (field) => {
this.setState(
{ [field] :'value'}
);
}