Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

101
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda