Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

185
Views
I am trying to update a property of an array of object but it is showing Cannot assign to read only property 'isSelected' of object

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 });
  };
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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 });
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!