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

103
Views
useState no se actualiza, después de usar set fuera de la función

componente funcional - reaccionar js Estoy ejecutando un proceso. Quiero detener ese proceso si el usuario hace clic en detener (el botón de detener está en un componente diferente - Modal)

la función de proceso en app.js parece

 const [terminate, setterminate] = useState(false); const process =()=>{ ... some code (has no use of terminate or setterminate) for(let i=0;i<5;i++){ if(terminate){ break } // api call } } // process function ends const stopProcess = ()=>{ setterminate(true) } // called a modal and passes stopProcess as prop. and when click stop button in modal, that invoke stopProcess function. but for loop insite process function dont get break

Modal.js

 ... <button onClick={stopProcess}></ button > ...

todo funciona bien, excepto que no se rompe. se invoca la función, probada por console.log("sdf")

¿Cómo rompo ese bucle de piso?

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

0

(clousers y funcionamiento de useState (async) y cómo se actualiza. (Lea eso primero)) para obtener inmediatamente el valor de useState

 let temp_terminate=false; setterminateProcess((state)=>{ temp_terminate=state; return state; })
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!