React.js
Angular
Ethical Hacking
Agile
AWS
BlockChain
Cassandra
Cloud
Salesforce
Scaled Agile
TOGAF
DevOps
GIT
Jenkins
Jira
Kibana
Linux
NGINX
Ansible
Artificial Intelligence
in React JS by

How to set state with a dynamic key name?

Click here to read more about DevOps

1 Answer

0 votes
by

If you are using ES6 or the Babel transpiler to transform your JSX code then you can accomplish this with computed property names.

handleInputChange(event) {
  this.setState({ [event.target.id]: event.target.value })
}

Related questions

Madanswer
0 votes
asked Jun 19 in React JS by JackTerrance
0 votes
asked Jul 2, 2019 in React JS by Venkatshastri
...