QuizNot attempted
Why immutability
1–4 to choose, Enter to submit
Show answer & explanation
Correct answer:
- React compares state with Object.is; the reference is unchanged, so it bails out
- React decides whether state changed with
Object.is - after mutating,
objis the same reference, sosetState(obj)bails out. - Create a new object:
setState({ ...obj, count: 1 }). - Not 'primitives only': state can be any value.
- Not 'throws in strict mode': JS allows mutating a non-frozen object, and StrictMode doesn't freeze state.
- Not 'delayed re-render': there is no re-render at all.
- Mutation also breaks memo and time-travel debugging.