Skip to content

Instantly share code, notes, and snippets.

@MostlyFocusedMike
Created July 5, 2018 01:32
Show Gist options
  • Save MostlyFocusedMike/cc5e8241d25830d1ee0c6430f86968cf to your computer and use it in GitHub Desktop.
Save MostlyFocusedMike/cc5e8241d25830d1ee0c6430f86968cf to your computer and use it in GitHub Desktop.
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