QuizNot attempted
Latest value via ref in an interval
1–4 to choose, Enter to submit
Show answer & explanation
Correct answer:
- Logs up-to-date values because
ref.currentis reassigned every render
- Every render executes
ref.current = count, and the interval readsref.current(a property of a stable object) rather than a captured variable, so it logs the latest value. - Not 'always 0': that is what reading
countdirectly would do. - Not 'throws' or undefined: the ref was initialised to
count. - Caveat: writing refs during render is discouraged under concurrent rendering
- update the ref in an effect or use
useEffectEvent(React 19.2).