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

141
Vistas
I use class to create an object in react component but when I try to set the state to the new object it doesn't rerender the component

I use a class to create an object in react component but when I try to set the state to the new object it doesn't rerender the component

Class:

class persons {

constructor(list = {}) {
this.list = list
} 

getPersons() {

return this.list
}
 
addPerson(person) {
this.list[someId] = person 
} 

}

in component when I add new person and set the state to the new list it didn't rerender the component like that:

//... 
const [personsList , setPersonsList] useState({}) 

const persons = new Persons(personsList)

persons.addPerson({name: "Mike"})
setPersonsList(persons.list)
//it doest also rerender with that

persons.addPerson({name: "Mike"})
setPersonsList(persons.getPersons)
//..

Although when I log persons.list or persons.getPersons() It shows the new list with the added person

about 4 years ago · Juan Pablo Isaza
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