title: how to clear input onchange validation message -ReactHooks
body: <p>I want to clear the input validation message after the validation is satisfied or the field is empty</p>
  <p>I have 2 inputs where have to validate numbers onchange itself.I am using react hooks</p>
  <p>code for onchange fields(can we format this 1 onchange)</p>
  <pre><code> const onChangePhNum = React.useCallback(
  (value: string) =&gt; {
    const FormattedValue1 =   onlynumberFormatter(value)
    props.setphoneNumber(FormattedValue1)
     /*clearMessage() */either any one of the message will be displayed
    if (FormattedValue1 === '' || FormattedValue1?.length &lt; 15) {
      setShowValidationMessage(true)
      setMessage(
        person.path,
        &quot;invalidPhoneNumber: length must be 10 digit&quot;,
      )
    }
  },
  [showValidationMessage, props.phoneNumber],
  )
  
  const onChangezipCode = React.useCallback(
  (value: string) =&gt; {
    const FormattedValue2 = noSpecialCharacters(value)
    props.setzipcode(FormattedValue2)
     /*clearMessage() */either any one of the message will be displayed
    if (FormattedValue2 === '' || FormattedValue2.length &lt; 4) {
      setShowValidationMessage(true)
      setMessage(
        person.path,
        &quot;invalidzipcode:zipcode must be 4 digit&quot;,
      )
    }
  },
  [showValidationMessage, props.zipCode],
  )
  </code></pre>
  <p>i have a clearMessage method also, but getting confused about when to call this</p>
  <pre><code>   const clearMessage = React.useCallback((message) =&gt; {
  if (showValidationMessage) {
    clearMessages(
      person.path,
      message,
    )
    setShowValidationMessage(false)
  }
  }, [showValidationMessage])
  </code></pre>