top of page
Writer's pictureSaurabh Singh

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


Html

JS


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;

to

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.




5,005 views1 comment

Subscribe to SFDC BLOGS

©2019 by SFDC Blogs.

bottom of page