Skip to content

Upload data of nested form does not work after spreading up components #774

Answered by NikRoe
gwittm asked this question in Web
Discussion options

You must be logged in to vote

Hi there,

in your RecipeForm you are currently calling the handleSubmit function twice.
For the form within this component and also for the form you call in this component (FormularIngredients).

The reason behind this is most likely that your ingredients state is part of the FormularIngredients component but you want to send the data, including the ingredients, whenever the RecipeForm form is submitted.

I would start by moving the ingredients state up to the RecipeForm.

export default function RecipeForm({ onSubmit, formName, defaultData }) {
const [ingredients, setIngredients] = useState([]);
//...
}

I would also move the part of the code where you map over the ingredients to the RecipeForm

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by NikRoe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Web
Labels
None yet
2 participants