Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

93
Visualizações
Reactjs IsNaN not validating inputs correctly

I have a readOnly input that calculates a value based on two other inputs (qty and price). In the getLineTotal() function, I am trying to validate the inputs and am having an issue when the input receives a blank value.

const getLineTotal = (e: any): void => {
        let parsedPrice: number;
        console.log(typeof e.target.value)
        if(Number.isNaN(e.target.value)){
            console.log("yes")
            parsedPrice = 0;
        }
        else{
            parsedPrice = parseInt(e.target.value);
        }
        setPrice(parsedPrice);
        console.log(qty, parsedPrice, "=>", qty * parsedPrice)
        setTotal(qty * parsedPrice);
    }

I have tried multiple different methods of detecting this NaN value, but nothing has worked. The console says it's a string but then says received NaN for value attribute.

string
LineDetail.tsx:38 12 12 '=>' 144
LineDetail.tsx:29 string
LineDetail.tsx:38 12 NaN '=>' NaN

Any ideas?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda