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

112
Vistas
IF statement on submit in React

I have this code and I'm trying to add some IF statements to the submit button, so it does not submit anything empty, or other than numbers and arithmetic operators, or shows error when operands are more than operators and vice versa, however it doesn't seem to work. Here is the full code.

const handleSubmit = (e) => {
  if (inputValue.length === 0) {
    e.preventDefault();
    setResult("You did not enter anything!")
  }
  if (inputValue === isNaN && inputValue !== validOperators) {
    e.preventDefault();
    setResult("only numbers!")
  } else {
    e.preventDefault();
    setResult(solution);
    setInputValue("");
  }
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

isNan is not a value, it's a function. You need to call it.

I made the assumption that validOperators is an array or a string containing the valid operators.

If so, this is what you want:

const handleSubmit = (e) => {
if (inputValue.length === 0) {
  e.preventDefault();
  setResult("You did not enter anything!")
} if (isNaN(inputValue) || !validOperators.includes(inputValue)) {
  e.preventDefault();
  setResult("only numbers (and valid operators)!")
} else {
  e.preventDefault();
  setResult(solution);
  setInputValue("");
 }
}

about 4 years ago · Juan Pablo Isaza Denunciar
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