QuizNot attempted
Cleanup on unmount
1–4 to choose, Enter to submit
Show answer & explanation
Correct answer:
mountthenunmount
Widgetmounts on the first render (showis true), so its effect logsmount- the click sets
showfalse,Widgetleaves the tree, and React runs its cleanup:unmount. - Not 'mount only': unmounting always runs cleanups.
- Not 'unmount only': the mount log already happened on the first render.
- Not nothing: effects with
[]still run once.