Skip to main content

Why are mutations inside Context values harmful?

Senior React
Quick Answer Mutations inside a Context value bypass React's change detection รขโ‚ฌโ€ the Context reference stays the same, so no consumer re-renders. Some see the new data, some see the old data, depending on when they last rendered. Always create new objects for Context values so React detects the change and triggers re-renders in all consumers.

Answer

Mutating context values bypasses reference changes, causing silent inconsistencies and unnecessary re-renders.
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