Resolve 'Cannot assign to read only property' error in LWC.

I stumbled upon this error when I was using data-table with checkboxes and I wanted to updated the selected property to true in main wrapper object. This issue generally occurs when your variable has some complex structure like object inside object.

Apex Controller



in function convertClick(), I was receiving this error when I was assigning 'selected' variable to true of this.wrap property.

to resolve this I just need to convert

let tempWrap = this.wrap;


let tempWrap = JSON.parse(JSON.stringify(this.wrap));

This is to clone a property without the references and when we assign this back to this.wrap, the issue would not arise.

©2019 by SFDC Blogs.