On submit the _addRecipe function gets called add it will push the value of the input and the textarea into the old state-object. On the first execution the function pushs a ne array in the object, but the folloing calls just overwrite the new added array…
In JavaScript, complex data types are always passed by reference. What this mean is essentially this in a JavaScript console:
var a = {}; var b = a; a == b; => true
In JavaScript, an Array is actually an Object, so the same applies.
For an Array, the best approach to take to create an actual copy is this:
var myArray = [1, 2, 3]; var myCopiedArray = myArray.slice(); myArray == myCopiedArray; => false
The Array method slice() returns a copy of the array, rather than modifying the array directly. When working with React, this is nearly always what you want. So I’d suggest something like this:
There are several more concise ways of accomplishing this, but the above will get you started.
For more information on this topic, I’d Google around for “javascript and immutability”. Also you may want to look at the ES6 spread operator, which makes the above super easy, once you become comfortable with the syntax: