0
I am using the Unform package to create a form in React and have the following function that renders the form:
function FormularioCliente() {
function handleSubmit(data) {
console.log(data);
}
return (
<Form onSubmit={handleSubmit}>
<div className="Nome">
<label>Nome: <Input name="nome" type="name" /></label>
</div>
<div className="Email">
<label>E-mail: <Input name="email" type="email" /></label>
</div>
<div className="Senha">
<label>Senha:<Input name="senha" type="password" /></label>
</div>
<div className="Botoes">
<button type="submit">Login</button>
</div>
<div>
<button type="asdasda">Cadastre-se</button>
</div>
</Form>
)
};
export default FormularioCliente;
The problem is that the method handleSubmit()
is called inside the tag Form
, Since I have more than one button inside, they all trigger the function and do the same thing. I would like each button to do something different, so I changed the code a little to call the function directly on <div />
that’s the button, and that <div />
is the daughter of <Form></Form>
. Stayed like this:
function FormularioCliente() {
function handleSubmit(data) {
console.log(data);
}
return (
<Form>
<div className="Nome">
<label>Nome: <Input name="nome" type="name" /></label>
</div>
<div className="Email">
<label>E-mail: <Input name="email" type="email" /></label>
</div>
<div className="Senha">
<label>Senha:<Input name="senha" type="password" /></label>
</div>
<div onSubmit={handleSubmit} className="Botoes">
<button type="submit">Login</button>
</div>
<div>
<button type="asdasda">Cadastre-se</button>
</div>
</Form>
)
};
export default FormularioCliente;
But when I click on the button I get the following console error message: TypeError: p is not a function
Why the fact that I call the function in a daughter tag disables my code?