QuizNot attempted
Stale count inside setInterval
1–4 to choose, Enter to submit
Show answer & explanation
Correct answer:
1
- The interval callback is created once (deps
[]) and closes over the mount render'scount = 0, so every tick callssetCount(0 + 1): the first tick sets 1, later ticks set the same value and bail out, and it is stuck at1. - Not 5: that needs
c => c + 1orcountin the deps. - Not 0: the first tick does update to 1.
- Not 'keeps incrementing': the stale closure never sees a value above 0.