Skip to content

Instantly share code, notes, and snippets.

@jsrath
Last active Nov 8, 2018
Embed
What would you like to do?
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