title: want to show validation error on handlechange using react hooks
body: <p>I am new to React 16, Please find the below code which I am using for Validation using hooks. I have used a reusable Select box and on the value of the option, I am showing an input box.
  Validation rules: if the select box is empty on click of submit i want to show error and hide it when I select a value then if the input box is empty want to show error and hide when we give valid input.
  Problem : When error message appears for select box and after selecting the value when input box appears it shows the error for that too so it's like the first look of input box is with the validation error. I want to show it when user clicks submit button and onchange after valid entry it should go away.</p>
  <p>Really appreciate the help!</p>
  <pre><code>  const Step3 = (props) =&gt; {
      const [values, setValues] = useState({});
      const [errors, setErrors] = useState({});
      const [isSubmitting, setIsSubmitting] = useState(false);
      const [isSent, setIsSent] = useState(false);
      const { handleChange, handleSubmit } = useForm(validate);
      useEffect(() =&gt; { if (Object.keys(errors).length === 0 &amp;&amp; isSubmitting) { } }, [errors]);
  
      const onChange = (event) =&gt; { 
          event.persist &amp;&amp; event.persist(); 
          setIsSubmitting(false);
          const newValues = {...values,[event.target.name]:event.target.value};
          isSent &amp;&amp; setErrors(validate(newValues));
          setValues(values =&gt; newValues);
       };
      const handleSubmit = (event) =&gt; { 
          if (event) event.preventDefault(); 
          setErrors(validate(values)); 
          setIsSubmitting(true); 
          setIsSent(true);
      };
  return (
      &lt;div&gt;
          &lt;form onSubmit={handleSubmit} noValidate&gt;
            &lt;Select
              name=&quot;abc&quot;
              label=&quot;ABC&quot;
              options={options}
              onChange={onChange}
              
          /&gt;
            {errors.abc &amp;&amp; (&lt;p className=&quot;help is-danger&quot;&gt;{errors.abc}&lt;/p&gt;)}
            
              {values.abc=='Apple' &amp;&amp; &lt;input name=&quot;xyz&quot; value={values.xyz||'' onChange={onChange}}/&gt;
                  {errors.xyz &amp;&amp; (&lt;p className=&quot;help is-danger&quot;&gt;{errors.xyz}&lt;/p&gt; )}
              }
              
            &lt;Button type={submit}&gt;
              Submit
            &lt;/Button&gt;
          &lt;/form&gt;
      &lt;/div&gt;
    );
  };
  
  function validate(values) {
       let errors = {}
       if (!values.abc)
       { errors.abc= ' required'; }
       if (!values.xyz) {
       errors.xyz= 'required'; 
       }
       return errors;
   };
  </code></pre>