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…
The whole code is on codepen
Here is the _addRecipe funtion:
_addRecipe(e, input, textarea) {
this.setState({
recipes: this.state.recipes.push({title: input, ingredients: setIngretients()})
});
console.log({title: input, ingredients: setIngretients()}, this.state.recipes);
console.log(this.state.recipes);
function setIngretients() {
var ingredients = [];
ingredients = textarea.split(',').map(function(ingredient) {
return ingredient;
});
return ingredients;
}
}