Skip to content

Instantly share code, notes, and snippets.

@jsrath
Last active November 8, 2018 21:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsrath/4eaeb37cc66a3bbfa00fa8ba48048da0 to your computer and use it in GitHub Desktop.
Save jsrath/4eaeb37cc66a3bbfa00fa8ba48048da0 to your computer and use it in GitHub Desktop.
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