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

159
Vistas
Updating the button type based on boolean value

I'm wondering is it possible to update the button type between "submit" & "button" based on a boolean value: form?.hasErrors)

Here's my code:

    const btnType = () => {
      if (form?.hasErrors) {
        return "submit";
      }
      return "button";
    };

    return (
      <>
          <StyledButton
            onClick={!form?.hasErrors() ? handleShowModal : undefined}
            type={btnType()}
          >
            Search
          </StyledButton>
   );

I basically just want to ensure that if the form has errors, that the button type is set to "submit" and if not, it will be set to "button" (default).

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I don't know why you want this. But i think you can use this.

  <StyledButton
    onClick={!form?.hasErrors() ? handleShowModal : undefined}
    type={form?.hasErrors() ? "submit": "button"}
  >
    Search
  </StyledButton>
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