Skip to content

Instantly share code, notes, and snippets.

@codingnninja
Created August 7, 2019 00:59
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 codingnninja/6626298d2abb0c17bc2bd6223ade3272 to your computer and use it in GitHub Desktop.
Save codingnninja/6626298d2abb0c17bc2bd6223ade3272 to your computer and use it in GitHub Desktop.
Update food items.
updateFoodItem(event) {
event.preventDefault();
const updatedFood = this.state.food;
const updatedCost = this.state.cost;
const updatedFoodItem = Object.assign({}, this.state.foodItem, { food: updatedFood, cost: updatedCost })
const foodItems = this.state.foodItems.map((foodItem) => (foodItem.id === this.state.foodItem.id ? updatedFoodItem : foodItem));
this.setState({ food:'', cost: '', foodItems: foodItems});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment