Skip to main content

Why must React state remain immutable?

Junior React
Quick Answer React uses object identity to detect changes. If you mutate an object in place (array.push, obj.x = 1), the reference doesn't change รขโ‚ฌโ€ React thinks nothing changed and skips re-rendering. Always create new objects/arrays for state updates so React sees a new reference and knows to update the UI.

Answer

React detects state changes using reference equality. Mutating state directly keeps the same reference, preventing React from re-rendering.
S
SugharaIQ Editorial Team Verified Answer

This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.

Want to bookmark, take notes, or join discussions?

Sign in to access all features and personalize your learning experience.

Sign In Create Account

Source: SugharaIQ

Ready to level up? Start Practice