This is a function which on click of an dropdown element changes a isSelected property to true or false and on the basis of isselected property it displays Cannot assign to read only property 'isSelected' of object
onCheckUsers = (x) => {
console.log(x, "param of x");
var { userFilter } = this.props.main;
var { length } = this.state;
var tempSelected = userFilter.find((a) => a.name === x.name);
if (tempSelected.isSelected) {
tempSelected.isSelected = false;
} else tempSelected.isSelected = true;
console.log(userFilter, "selectedUserList");
StoreActions.setState({ userFilter });
length = userFilter.filter((d) => d.isSelected).length;
this.setState({ length });
// Actions.storeSetState({ userFilter });
};
So here i found the answer by myself that you cannot update the state of a redux store directly so for that you need to update the state in the current context and then assign the value to it. I am not really sure weather its the right explanantion or not but for me it worked. so here i am attching the code if anyone feels to optimise it please you are welcome
var { userFilter } = this.props.main;
var { length , tempSelected=[]} = this.state;
var tempSelected = _.cloneDeep(userFilter);
var newtemplist= tempSelected.find((a) => a.name === x.name)
if (newtemplist.isSelected) {
newtemplist.isSelected = false;
} else newtemplist.isSelected = true;
this.setState({tempSelected:newtemplist})
console.log(userFilter, "selectedUserList");
StoreActions.setState({ userFilter:tempSelected });