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

181
Vistas
React - Show modal when user clicks on submit, don't hit endpoint until modal button clicked

I have a standard form in react thats built with react final form. When the user clicks submit, I show a modal to them by updating state to reveal the modal. The modal has two options which update state. I want to wait for one of the options to be clicked before firing the post endpoint.

Here is the form

  <div>
    <Wrapper>
      <Form
        onSubmit={onSubmit}
        render={({ handleSubmit }) => (
          <form onSubmit={handleSubmit} noValidate>
            // Fields are here
            <Modal
              isOpen={showModal}
              handleAcceptClick={handleAcceptClick}
              handleDeclineClick={handleDeclineClick}
            />
            <Button
              buttonType="submit"
            />
          </form>
        )}
      />
    </Wrapper>
  </div>

// This is the onSubmit methiod

  async function onSubmit(submission: Payload) {
    setShowModal(true);
    
    await api.create({
      submission,
    });
  }

In the modal component theres a callback to setstate in the same file the form is in, based on if they accept or deny. How can I wait for that state happen before I call the api.create method in on submit.

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

0

HTML:

<div>
    <Wrapper>
        <Form
        onSubmit={onSubmit}
        render={({ handleSubmit }) => (
        <form onSubmit={handleSubmit} noValidate>
        // Fields are here
            <Modal
                isOpen={showModal}
                handleAcceptClick={handleAcceptClick}
                handleDeclineClick={handleDeclineClick}
            />
            <Button
                buttonType="button"
                onClick={confirm}
            />
        </form>
        )}
        />
    </Wrapper>
</div>

JS CODE:

function confirm() {
    setShowModal(true);
}

// call this function on click of one option in modal
function onConfirm(){
    onSubmit();
}
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