QuizNot attempted
Plain variable vs ref with no re-render
1–4 to choose, Enter to submit
Show answer & explanation
Correct answer:
local var: 1, ref: 0,local var: 2, ref: 0,local var: 3, ref: 0
- Nothing triggers a re-render, so the same
handleClickclosure (and the samecountvariable) is reused and increments 1, 2, 3, whilecountRef.currentwas initialised to 0 and is never written. - Not 1 all three times: that would need a re-render that recreates
count = 0. - Not ref 1, 2, 3: the handler only changes the local variable.
- Not 'throws':
countis alet, reassignment is fine. - (After any real re-render, the local
countwould reset to 0.)