Bird
0
0

How can you prevent a dumb component from accidentally mutating an input array passed from a smart component?

hard📝 Application Q9 of 15
Angular - Advanced Patterns
How can you prevent a dumb component from accidentally mutating an input array passed from a smart component?
AUse @Output to send the array back to the smart component for modification.
BMark the input property as readonly in the dumb component.
CDisable change detection in the dumb component.
DCreate a copy of the array inside the dumb component before modifying it.
Step-by-Step Solution
Solution:
  1. Step 1: Understand mutation risks

    Inputs are references; modifying them directly changes parent data.
  2. Step 2: Choose safe modification method

    Creating a copy inside dumb component avoids mutating the original array.
  3. Final Answer:

    Create a copy of the array inside the dumb component before modifying it. -> Option D
  4. Quick Check:

    Clone inputs before modifying to avoid side effects [OK]
Quick Trick: Clone arrays before changing in dumb components [OK]
Common Mistakes:
  • Assuming readonly prevents mutation at runtime
  • Expecting dumb components to modify inputs directly
  • Disabling change detection to fix mutation issues

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes