QuizNot attempted
Empty dependency array: mount and unmount
1–4 to choose, Enter to submit
Show answer & explanation
Correct answer:
mounted(once) →cleanup(once, on unmount)
- With
[]the effect has no dependencies to change, so it runs once after mount and its cleanup runs once on unmount - clicks re-render but never re-run it.
- Not mounted/cleanup per click: that is what a
[count]dependency would do. - Not 'mounted → cleanup' immediately: cleanup waits for unmount (StrictMode dev adds an extra mount/cleanup, but that is a dev check).
- Not 'three mounts, no cleanup': the effect doesn't re-run, and the returned cleanup always runs on unmount.