I want to change my state, the user properties, when the you change the field on the form I want it to change the proper value on user.
My element that I'm passing the function to, is to handle the value and fill the state in the parent component.
Ex: user type password. I want the user object to keep the same, but the user has to change.
state = {
signUp: true,
user:{
name: '',
password: '',
email: '',
userName: ''
}
}
handleChange = e =>{
this.setState(prevState => ({
user: {
...prevState.user,
[e.target.name] : e.target.value
}
}
));
}
export default function SignupForm({handleSignup, handleChange}) {
return (
<div>
<div className='login-page__main__cadastro'>
<h4>
Cadastre-se para ver<span className='br'><br></br></span> fotos e vídeos dos seus <span className='br'><br></br></span> amigos.
</h4>
<form className='login-page__main__cadastro__form'>
<input className='form-cadastro-item' onChange={handleChange} name='email' type='email' placeholder='email'></input>
<input className='form-cadastro-item' onChange={handleChange} name='name' type='text' placeholder='Nome completo'></input>
<input className='form-cadastro-item' onChange={handleChange} name='userName' type='text' placeholder='Nome de usuário'></input>
<input className='form-cadastro-item' onChange={handleChange} name='password' type='password' placeholder='Senha'></input>
<button onClick={handleSignup} className='btn-primary'>
Cadastrar-se
</button>
</form>
</div>
</div>
)
}
I'm getting an error: e.target is null.