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!