I was trying to do that when the user pressed the submit button, he would check what the user entered, and if it was not valid he would send an error message through the span.Obs: I cut the code for easier reading, but the problem is in this part.
import React from 'react';
export class FormSignUp extends React.Component{
constructor(){
super();
this.state = {
firstName: '',
lastName: '',
email: '',
password: '',
rePassword: '',
day:'default',
month: 'default',
year: 'default',
gender:'1'
};
}
changeInp = e =>{
this.setState({
[e.target.name]: e.target.value
});
};
errors = {
nameError: ''
}
onSubmit = (e) => {
e.preventDefault();
if(this.state.firstName.length < 3){
this.errors.nameError = 'ta errado isso dai';
}
alert('submit');
console.log(this.state);
}
render(){
return(
<div className='formSignUp'>
<div className='fullSameInputS'>
<form>
<div className='nameDiv halfInput'>
<input type="text" name='firstName' value={this.state.firstName} onChange={e => this.changeInp(e)} className='signUpFstNameInput' placeholder='Nome'/>
<span>{this.errors.nameError}</span>
</div>