QuizNot attempted
useMemo with empty deps and Math.random
1–4 to choose, Enter to submit
Show answer & explanation
Correct answer:
- Number never changes after mount; logs 1 time total
- With
[]the memo computes once on mount and every later render reuses the cachedMath.random()value, so the number never changes and the log fires once. - **Not 'changes each click
- logs 6':** that is code without memoization.
- Not 'logs 5': if it re-ran, the number would also change.
- Not 'odd clicks': nothing alternates.
- (React may discard memo caches in rare cases, so don't use useMemo for correctness.)