Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

186
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda