Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

86
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda