Last active
August 19, 2021 19:18
-
-
Save becauro/eb6d306164b61a3067c39ea442e2074a to your computer and use it in GitHub Desktop.
How to set a Favorite content to LocalStorage. In this case, the content come from recipeDetail Props
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
addToLocalStorage() { | |
const { id, type, recipeDetail: { strArea, strCategory, | |
strAlcoholic, strDrink, strMeal, strMealThumb, strDrinkThumb } } = this.props; | |
const favoriteRecipes = JSON.parse(getItem('favoriteRecipes')) || []; | |
const newFavoriteRecipe = [ | |
...favoriteRecipes, | |
{ | |
id, | |
type: type.replace('s', ''), | |
area: strArea || '', | |
category: strCategory || '', | |
alcoholicOrNot: strAlcoholic || '', | |
name: strMeal || strDrink, | |
image: strDrinkThumb || strMealThumb, | |
}, | |
]; | |
setItem('favoriteRecipes', JSON.stringify(newFavoriteRecipe)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment