Salesforce Decode
Salesforcedecode
Back to questions
LWCIntermediateapisecurityerror-handling

Validate @api object props with deep clone before mutating child state

Real World Scenario

Child LWC mutates @api config object in place causing parent state corruption and subtle re-render loops.

Expected Answer

• Deep clone @api objects on receive before local mutation • Treat @api as immutable from child perspective • Parent passes new object reference on intentional update • Avoid @api side effects in setter triggering parent cascade • JSON parse stringify clone for plain config objects • Document @api contract read-only in component README • Jest test child does not mutate parent passed object reference

Follow-Up Questions & Answers

Click to expand — each follow-up includes a direct, interview-ready answer

Direct answer: Deep clone @api objects on receive before local mutation Also consider: Treat @api as immutable from child perspective In practice: Parent passes new object reference on intentional update Balance speed of delivery with maintainability.

Architect Perspective

Mutating @api props breaks LWC data flow—clone on entry is defensive standard.