Created
April 17, 2018 03:29
-
-
Save ryanjyost/cc9a2743f08346ea36697012a83b4563 to your computer and use it in GitHub Desktop.
deleteItem() with localStorage
This file contains hidden or 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
| 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