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

178
Views
Reaccionar: cómo verificar la igualdad de la variable de estado declarada con useState ()

En el siguiente ejemplo, declaro una variable myVar con el gancho useState(). Estoy tratando de verificar su valor y, de acuerdo con esto, hacer algunas cosas. Sé a través del gancho useEffect() que myVar tiene el valor que se supone que debe tener. Aunque cuando trato de verificar si es igual a algún valor en las declaraciones if, esas comparaciones claramente se calculan incorrectamente. ¿Hay alguna solución para comprobar el valor de la variable myVar ? ¡Gracias de antemano!

 const Example = () => { const [myVar, setMyVar] = useState(0); useEffect(() => { // Consoles the correct value console.log(myVar); }, [myVar]) useEffect(() => { (async () => { if (!loading) { await runAnimation(); } })() }, [loading]) const runAnimation = async () => { setMyVar(myVar + 1); someFunction(); } const someFunction = async () => { response = await controls.start(); // Gets in wrong statements if (myVar === 0) { doZero(); } else if (myVar === 1) { doOne(); } else if (myVar === 2) { setMyVar(myVar - 1); doTwo(); } } return ( <div> <SomeComponents /> </div> ) }
about 4 years ago · Juan Pablo Isaza
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!