Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

179
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!