Created
July 5, 2018 01:32
-
-
Save MostlyFocusedMike/cc5e8241d25830d1ee0c6430f86968cf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Form extends React.Component { | |
state = { | |
cats: [{name:"", age:""}], | |
owner: "", | |
description: "" | |
} | |
handleChange = (e) => { | |
if (["name", "age"].includes(e.target.className) ) { | |
let cats = [...this.state.cats] | |
cats[e.target.dataset.id][e.target.className] = e.target.value | |
this.setState({ cats }, () => console.log(this.state.cats)) | |
} else { | |
this.setState({ [e.target.name]: e.target.value }) | |
} | |
} | |
// ...rest of component |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment