QuizNot attempted
Lazy initializer runs once
1–4 to choose, Enter to submit
Show answer & explanation
Correct answer:
- 1
- Passing a function (
useState(() => ...)) tells React to call it only on the initial render - later renders ignore it, so it logs once.
- Not 0: it must run once to produce the initial value.
- Not 3 or 4: that would happen with
useState(compute()), which evaluates on every render (the result is just ignored).