# I need help with Recipe Box

**URL:** <https://forum.freecodecamp.org/t/i-need-help-with-recipe-box/177192>\
**Category:** General\
**Created:** [February 28, 2018, 3:58pm UTC](https://forum.freecodecamp.org/t/i-need-help-with-recipe-box/177192 "2018-02-28T15:58:08Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![MukeshAngrish](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/mukeshangrish/32/79951_2.png) [@MukeshAngrish](https://forum.freecodecamp.org/u/MukeshAngrish)\
**Post date:** [February 28, 2018, 3:58pm UTC](https://forum.freecodecamp.org/t/i-need-help-with-recipe-box/177192/1 "2018-02-28T15:58:09Z")

</div>

Hey everyone. I have been racking my brain trying to figure out the issue with my React Recipe Box. I have searched through every part of the code to find the cause of the issue, but I have wasted far too many hours staring at my code. I also requested help in the Gitter chat a few time, but the responses were rare.  
Whenever I fix an error, a new one arises. And after a few iterations, I get the same error I got in the beginning of the day. “Back to square one! 😔” I have wasted two days doing the same. And now I’m exhausted.

1. Buttons randomly don’t work
2. If I comment few cases in the `modifyRecipe()` the other cases work fine. But not together  
I want to move onto next project or learn more about React. But I’m stuck and for the last two days I’ve learned nothing useful.  
Here is the link to my project : [React Recipe Box](https://codepen.io/MukeshAngrish/pen/WMLLjR?editors=0011)  
The text is editable with a click on the text itself. For adding use the the large + to add a recipe and small + to add an ingredient. For deletion options use the pencil icon. Also the text is horizontally scrollable.  
Help me please.

---

<div class="post-metadata">

**Author:** ![JohnnyBizzel](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/johnnybizzel/32/37661_2.png) [@JohnnyBizzel](https://forum.freecodecamp.org/u/JohnnyBizzel)\
**Post date:** [March 1, 2018, 11:56am UTC](https://forum.freecodecamp.org/t/i-need-help-with-recipe-box/177192/2 "2018-03-01T11:56:13Z")

</div>

It looks stylish but it seems you cannot type in any text for a new recipe.  
I see a problem now. You have the `modifyRecipe` function which changes depending on what the user does. In each case you have a set state `this.setState({ myRecipeBox });`  
This will force a rerender every time the event is fired for example when the user is typing a new ingredient for every keystroke the user is forcing a re-render.  
eg) for “Saffron”, 7 letters so 7 re-renders.  
I suggest using a “SAVE CHANGES” button and do the setState on the button press event.

---

<div class="post-metadata">

**Author:** ![JohnnyBizzel](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/johnnybizzel/32/37661_2.png) [@JohnnyBizzel](https://forum.freecodecamp.org/u/JohnnyBizzel)\
**Post date:** [March 5, 2018, 12:59am UTC](https://forum.freecodecamp.org/t/i-need-help-with-recipe-box/177192/3 "2018-03-05T00:59:44Z")

</div>

I’ve been having a go at improving your code.  
I’m not finished but have made some progress:

> **[Recipe Box-mukesh](https://codepen.io/JohnnyBizzel/pen/mXvQGG)**
>
> ...

Note that I have added IDs to the recipes. The reason is that although each recipe should have a different name, there is a possibility that 2 recipes have the same name. Giving IDs solves this issue.

---

<div class="post-metadata">

**Author:** ![MukeshAngrish](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/mukeshangrish/32/79951_2.png) [@MukeshAngrish](https://forum.freecodecamp.org/u/MukeshAngrish)\
**Post date:** [March 5, 2018, 5:08pm UTC](https://forum.freecodecamp.org/t/i-need-help-with-recipe-box/177192/4 "2018-03-05T17:08:49Z")

</div>

Hey @JohnnyBizzel, thanks for looking into this matter. I appreciate you have improved the code. Sorry for the late reply but I had a very hard time making that code function properly, so I created a new [Recipe Box](https://codepen.io/MukeshAngrish/pen/QQPXPY?editors=0111) from the start. I have fundamentally replaced most of the functional aspect of the code, while retaining the look. But it seems like trouble is not leaving me 😅 .The ingredients are not showing up yet. And I still have to figure out how I can edit the text in the same way as we can change the pen names in CodePen. That way it won’t re-render at every letter like you said. Also I have also added IDs to recipes like you did. I hope I complete this soon.

---

<div class="post-metadata">

**Author:** ![JohnnyBizzel](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/johnnybizzel/32/37661_2.png) [@JohnnyBizzel](https://forum.freecodecamp.org/u/JohnnyBizzel)\
**Post date:** [March 5, 2018, 5:26pm UTC](https://forum.freecodecamp.org/t/i-need-help-with-recipe-box/177192/5 "2018-03-05T17:26:52Z")

</div>

Not sure about the edit names on codepen style. I recommend keeping things simple to begin with and then trying to do clever stuff.  
The save event should be separate from the typing event.

---

<div class="post-metadata">

**Author:** ![MukeshAngrish](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/mukeshangrish/32/79951_2.png) [@MukeshAngrish](https://forum.freecodecamp.org/u/MukeshAngrish)\
**Post date:** [March 6, 2018, 4:43pm UTC](https://forum.freecodecamp.org/t/i-need-help-with-recipe-box/177192/6 "2018-03-06T16:43:55Z")

</div>

@JohnnyBizzel I have made some progress with [this one](https://codepen.io/MukeshAngrish/pen/QQXepJ?editors=1111). It’s almost complete. One issue I’m facing though is that I can’t edit more than I character right now. Can you help me with that?

---

<div class="post-metadata">

**Author:** ![JohnnyBizzel](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/johnnybizzel/32/37661_2.png) [@JohnnyBizzel](https://forum.freecodecamp.org/u/JohnnyBizzel)\
**Post date:** [March 7, 2018, 10:05am UTC](https://forum.freecodecamp.org/t/i-need-help-with-recipe-box/177192/7 "2018-03-07T10:05:46Z")

</div>

Same problem as before:

```auto
<input className = "recipe-name-input"
	onChange = { this.handleNameUpdate }
	value = { this.props.name } />

```

on change of the text box

```auto
	updateRecipe(index, name, ingredients) {
		let { recipes } = this.state;
		recipes[index].name = name;
		recipes[index].ingredients = ingredients;
		this.saveRecipes(recipes);
		console.log(JSON.stringify(recipes));
	}

```

you update the state.  
The state should get updated on the save event.

> [@JohnnyBizzel](#):
>
> I suggest using a “SAVE CHANGES” button and do the setState on the button press event.

---

<div class="post-metadata">

**Author:** ![JohnnyBizzel](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/johnnybizzel/32/37661_2.png) [@JohnnyBizzel](https://forum.freecodecamp.org/u/JohnnyBizzel)\
**Post date:** [March 7, 2018, 11:00am UTC](https://forum.freecodecamp.org/t/i-need-help-with-recipe-box/177192/8 "2018-03-07T11:00:23Z")

</div>

I would also recommend using refs.  
I have done the editing of the header using that method.  
` this.props.handleChange('modifyName', this.props.id, this.refs.recName.value);` line 293

```auto
        <input 
          className = 'recipe-name' ref="recName"
          value = { this.state.recipeName }
          onChange = { this.modifyName }>

```

ref comes from the attribute.

> **[Recipe Box-mukesh](https://codepen.io/JohnnyBizzel/pen/mXvQGG)**
>
> ...

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 17, 2021, 8:25pm UTC](https://forum.freecodecamp.org/t/i-need-help-with-recipe-box/177192/9 "2021-01-17T20:25:00Z")

</div>

Closed on January 17, 2021, 8:25pm UTC


