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

185
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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