-1
I’m making a revenue registration page. This is my form:
<form onSubmit={handleSubmit}>
<Input
name="title"
label="Nome da receita:"
type="text"
value={title}
onChange={(event) => { setTitle(event.target.value)}}
/>
<div>
<table>
<thead>
<tr>
<th>Ingrediente</th>
<th>Quantidade</th>
</tr>
</thead>
</table>
</div>
<div >
<Input
name="ingredient"
label=""
type="text"
value={ingredient}
onChange={(event) => { setIngredient(event.target.value)}}
/>
<Input
name="quant"
label=""
type="text"
value={quant}
onChange={(event) => { setQuant(event.target.value)}}
/>
</div>
<button onClick={handleIngredient}>
Incluir ingrediente
</button>
<TextArea
name='direction'
label='Modo de fazer:'
type="text"
value={direction}
onChange={(event) => { setDirection(event.target.value)}}
/>
<div>
<button type="submit">
Cadastrar receita
</button>
</div>
</form>
When the user clicks on the Include ingredient button, I would like the page to show two more inputs, one for the ingredient and one for the quantity. So far I have created the following. (This snippet is called in the handleIngredient function):
function handleIngredient( ){
<>
<div>
<Input
name="ingredient"
label=""
type="text"
value={ingredient}
onChange={(event) => { setIngredient(event.target.value)}}
/>
<Input
name="quant"
label=""
type="text"
value={quant}
onChange={(event) => { setQuant(event.target.value)}}
/>
</div>
<button onClick={handleIngredient}>
Incluir ingrediente
</button>
</>
}
But it does not return the inputs, and the worst: it returns the content of handleSubmit. So I have these two questions: How do I create these two inputs from the click of the button; Why this button (which is not Submit) calls the Submit function.
Thank you all.