import React,{useState} from 'react'
const initialState = { nombre: "" ,apellidos: "" ,email: "" ,contrasena: "" ,repetirContrasena: "" };
enter code here
const handleSubmit=(e)=>{
e.preventDefault();
console.log(formData);
};
const handleChange = (e) =>{
setFormData({ ...formData,[e.target.name]: e.target.value});
};
return(
<form className={classes.form} onSubmit={handleSubmit}>
<Grid container spacing={2}>
{isSignup &&(
<>
<Input name="nombre" type="text" label="Nombre" handleChange={handleChange} autoFocus medio />
<Input name="apellidos" type="text" label="Apellidos" handleChange={handleChange} medio />
</>
)}
<Input name="email" label="Email" handleChange={handleChange} type="email" />
<Input name="contrasena" label="Contrasena" handleChange={handleChange} type={showPassword ? "text" : "password"} handleShowPassword={handleShowPassword} />
{ isSignup && <Input name="repetirContrasena" label="Repetir Contrasena" handleChange={handleChange} type="password" />}
</Grid>
This is the result.
{nombre: "", apellidos: "", email: "", contrasena: "", repetirContrasena: "", …}
**"": "123"
apellidos: "" contrasena: "" email: "" nombre: "" repetirContrasena: "" proto: Object** Error image
I tried using onChange={handleChange},onInput={handleChange} instead handleChange={handleChange} but the result gets completly empty.