Skip to content

Instantly share code, notes, and snippets.

@ryanjyost
Created April 17, 2018 03:29
Show Gist options
  • Select an option

  • Save ryanjyost/cc9a2743f08346ea36697012a83b4563 to your computer and use it in GitHub Desktop.

Select an option

Save ryanjyost/cc9a2743f08346ea36697012a83b4563 to your computer and use it in GitHub Desktop.
deleteItem() with localStorage
deleteItem(id) {
// copy current list of items
const list = [...this.state.list];
// filter out the item being deleted
const updatedList = list.filter(item => item.id !== id);
this.setState({ list: updatedList });
// update localStorage
localStorage.setItem("list", JSON.stringify(updatedList));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment