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

100
Views
React TypeScript copy enum value and not reference

I have a question regarding variables and references in React TypeScript or JavaScript if you want.

I have the following enum:

enum QuestionType {
  MultipleChoice,
  TrueFalse,
  FreeText
}

And my code looks like this (simplified):

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

I expect the following outcome:

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

But the actual outcome is the following:

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

I already read on some posts that js only stores references to values and that a simple '=' will just create a new reference to that value. But I am so confused on how I get this to work properly.

Thank you in advance!

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!