QuizNot attempted
Mutating state and setting the same object
1–4 to choose, Enter to submit
Show answer & explanation
Correct answer:
1
setObj(obj)passes the same reference, and React bails out whenObject.is(old, new)is true, so nothing re-renders and the DOM still shows1even thoughobj.ais 5 in memory.- Not 5: the mutation never triggers a render, so it never reaches the DOM (until something else re-renders).
- Not an error: mutating state is a bug, not a thrown exception.
- Not undefined:
astill exists on the object. - Fix:
setObj({ ...obj, a: 5 }).