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

104
Views
Espere a que termine una función, antes de que se ejecute la siguiente

Tengo una aplicación de reacción. En él, cuando un usuario accede al formulario, quiero abrir un modal y almacenar la respuesta de los usuarios en el estado. En base a esta respuesta, quiero realizar alguna lógica comercial y luego publicar el formulario.

Este es mi método onsubmit

 async function onSubmit(submission: IPayload) { await handleModal(); await submit(submission); } async function submit(submission: ICreateAdPayload) { await api.create({ this is where all the props go}) } // Heres I set the state of the modal to open, which then chanes the open prop on another component for the modal to open. async function handleModal(submission: any) { setShowModal(true); // handle logic setShowModal(false); }

Sin embargo, mi función de envío se lleva a cabo tan pronto como se abre el modal. ¿Alguna idea?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Para poder await handleModal(...) , entonces ese método debe devolver una Promise que se resolve cuando el trabajo ha terminado, suponiendo que no necesite await nada, NO necesita estar marcado como async

 function handleModal(submission: any) { setShowModal(true); return new Promise(resolve => { // handle logic setShowModal(false); resolve(); }); }
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!