Including validation on a form improves the user experience, by giving them immediate feedback on whether the information entered is valid. In this section, we are going to add validation to our Form component and then consume it in our ContactUs component.
The validation rules we are going to implement in the ContactUs component are these:
- The name and email fields should be populated
- The name field should be at least two characters
We are going to execute validation rules when the field editor loses focus.
In the next section, we'll add a prop to the Form component that allows consumers to specify validation rules.