How could I edit a recipe object inside an array of recipe objects

user8840209

I am making a recipe box project using React, and to edit the existing recipe, I tried this code, this.state.recipe is currently an array of recipe objects:

editRecipe = (recipe) => {
  this.state.recipe.find(obj => obj.name === recipe.name).name = recipe.name;
  this.state.recipe.find(obj => obj.name === recipe.name).ingredients = recipe.ingredients;
}

And pass this method to the <EditRecipe edit={this.editRecipe} /> as a prop. However, when I activate the method in that component than invoke the edit prop, there is an error message that says : "this.state.recipe.find(...) is undefined"

Is there any other approach to edit the recipe?

Here is the error message that I got enter image description here

Thank you.

Rohith Murali

It should have the this avalable for the EditRecipe component, so change the way you pass the function as props

<EditRecipe edit={this.editRecipe.bind(this)} />

Also you should change the function as,

editRecipe = function(recipe){
  let selectedObj;
  selectedObj = this.state.recipe.find(obj => obj.name === recipe.name)
  if(selectedObj){
    selectedObj.name = recipe.name;
    selectedObj.ingredients =recipe.ingredients;
  }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I change or edit Vim Homebrew recipe?

How do I search for a vault item from inside a recipe?

How do I set a variable inside a recipe using a case statement?

How to include_recipe inside a ruby_block of a chef recipe

How can I scrape this recipe?

How would you store a recipe inside a json?

How do I edit '/etc/ld.so.conf' in a yocto recipe?

How to reduce the size of a preprocessing recipe object in r?

How do I view a recipe on a chef server?

how do i use itemStack in recipe

How do I check if Chef's version mets a gem requirement from inside a recipe?

Recipe directions to array in PHP

How to mutate a list-column using purrr::map() to store a "recipe" object created via recipe()?

How to run a Chef recipe

How to maintain idempotency in a recipe

Objects are not valid as a React child (found: object with keys {Dname, recipe_diet}). If you meant to render a collection of children, use an array

How can I run a Make recipe within another Make recipe with a loop?

How do I filter an array object inside of a array of objects Javascript?

How can I use array filter to find value of value inside an object inside an array and then change/edit that value?

How can I display an array of objects inside a object in React?

How can I reorder an ELEMENT inside of an OBJECT of an array of OBJECTS NOT sort?

'recipe' is not defined when mapping a array

Can I tag a node in a recipe?

How do I rename a recipe and replace it on the run list of all nodes

How can I create multiple files using chef recipe?

How do I use a Launchpad recipe for patching and building an original package?

How do I get Lando mysql portforward to work with lamp recipe

How can I conditionally run a block of resources or a recipe in chef?

How can I add a folder or file to the root in a recipe with bitbake?