1
I’m having trouble finding a solution to clear the fields input after clicking the button calculate.
Follow code in simplified form
function EqBernoulli2 () {
  const [Pt, setPt] = useState('')
  const [Ps, setPs] = useState('')
  const [V, setV] = useState('')
  const [ρ, setρ] = useState('')
  const [resultado3, setResultado3] = useState()
  function calcular3 () {
    if (V == '') {
      let Prest = Math.sqrt(parseFloat((2 * (Pt - Ps)) / ρ))
      setResultado3(Prest)
    }
  }
  return (
    <div className='eqbernoulli'>
      <EqBernoulliM>
        <h2>Calculo: </h2>
        <p className='obs'>
          <i>Obs:</i>
        </p>
        <div className='input'>
          <label htmlfor='nome'>
            P<sub>t</sub> =
          </label>
          <input
            className='pressão1'
            type='number'
            id='pressão1'
            required='required'
            value={Pt}
            onChange={e => setPt(e.target.value)}
          />
        </div>
        <div className='input'>
          <label htmlfor='nome'>
            P<sub>s</sub> =
          </label>
          <input
            className='velocidade1'
            type='number'
            id='velocidade1'
            required='required'
            value={Ps}
            onChange={e => setPs(e.target.value)}
          />
        </div>
        <div className='input'>
          <label htmlfor='nome'>V =</label>
          <input
            className='altura1'
            type='number'
            id='altura1'
            required='required'
            value={V}
            onChange={e => setV(e.target.value)}
          />
        </div>
        <div className='input'>
          <label htmlfor='nome'>ρ =</label>
          <input
            className='pressão1'
            type='number'
            id='pressão2'
            required='required'
            value={ρ}
            onChange={e => setρ(e.target.value)}
          />
        </div>
        <button className='calcular2' id='calcular' onClick={calcular3}>
          Calcular
        </button>
        <div className='result' id='resultado'>
          {resultado3}
        </div>
      </EqBernoulliM>
    </div>
  )
}
						
Updating the state to an empty string does not work? For example,
setPt(''). What you tried and what was the problem?– Rafael Tavares
I did not try to update the status. What I imagined I could not put into practice. I am new in the area and in certain situations I feel a little stuck.
– Mpimenta