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
Reaccionar valor de enumeración de copia de TypeScript y no referencia

Tengo una pregunta sobre variables y referencias en React TypeScript o JavaScript si lo desea.

Tengo la siguiente enumeración:

 enum QuestionType { MultipleChoice, TrueFalse, FreeText }

Y mi código se ve así (simplificado):

 //somewhere in an useEffect hook //using the useState hook setSelectedQuestionType(QuestionType.TrueFalse); let previousQuestionType : QuestionType; prevQuestionType = selectedQuestionType; setSelectedQuestionType(QuestionType.MultipleChoice);

Espero el siguiente resultado:

 console.log(selectedQuestionType); //Expected: QuestionType.MultipleChoice or 0 console.log(prevQuestionType); //Expected: QuestionType.TrueFalse or 1

Pero el resultado real es el siguiente:

 console.log(selectedQuestionType); //Actual: QuestionType.MultipleChoice or 0 console.log(prevQuestionType); //Actual: QuestionType.MultipleChoice or 0

Ya leí en algunas publicaciones que js solo almacena referencias a valores y que un simple '=' simplemente creará una nueva referencia a ese valor. Pero estoy tan confundido sobre cómo hago para que esto funcione correctamente.

¡Gracias de antemano!

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!