Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

180
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda