I have a function which retrieves an object.
const removeLogo = (values: any) => {
values.settings.logoUrl = undefined;
setMaster({ ...values });
};
my object is the following :
values = {
name: "test",
reference: "ref"
settings: {
logoUrl : 'url'
}
}
in this object I simply want to change a value :
values.settings.logoUrl = undefined;
but I end up with a following error message :
form-mail-reminders.tsx:83 Uncaught TypeError: Cannot assign to read only property
'logoUrl' of object '#<Object>'
Is there a solution to modify the value of the object without having this error message ?
You need to set the property of the objects to writeable as they are set to non writeable.
writable
true if and only if the value associated with the property may be changed with an assignment operator. Defaults to false.
And for you:
Object.defineProperty(values, 'logoUrl', {
writable:true
});