Last active
November 8, 2018 21:04
-
-
Save jsrath/4eaeb37cc66a3bbfa00fa8ba48048da0 to your computer and use it in GitHub Desktop.
This file contains 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
handleSave = async () => { | |
if (!this.state.editing.id) { | |
const newId = Math.max(...this.state.contacts.map(contact => contact.id)) + 1; | |
let editing = { ...this.state.editing }; | |
editing.id = newId; | |
await this.setState({ editing }); | |
} | |
const idToUpdate = this.state.editing.id; | |
const duplicate = [...this.state.contacts].filter(contact => contact.id !== idToUpdate); | |
this.setState({ contacts: [...duplicate, this.state.editing] }, () => this.toggleModal()); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment