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

306
Visualizações
Cannot add property 0, object is not extensible when trying to push class-constructed objects indo an array list - React/NextJs

This is the code involved in that function, the goal is to create rows for rendering in a Material Ui table.

class User {
            constructor(id, name, email, measured, offset, paidAmount, status, home, misc, plane, transport, partner, isCoupon) {
                this.id = id
                this.name = name
                this.email = email
                this.measured = measured
                this.offset = offset
                this.paidAmount = paidAmount
                this.status = status
                this.home = home
                this.misc = misc
                this.plane = plane
                this.transport = transport
                this.partner = partner
                this.isCoupon = isCoupon
    
            }
        }
    
        const mountTableRows = () => {
            rawData.map((item, index) => {
                let user = {}
                user = new User(
                    item["ulid"],
                    item["Name"],
                    item["Email"],
                    item["Emissions"],
                    item["Quantity"],
                    item["Value"],
                    item["Status"],
                    item.Rawresult["home"],
                    item.Rawresult["misc"],
                    item.Rawresult["plane"],
                    item.Rawresult["transport"],
                    item["Partner"],
                    item["isCoupon"]
                )
                usersList.push(user)
            })
            setIsListMounted(true)
        }
    
        useEffect(() => {
            if (rawData.length > 0 && !isListMounted) {
                mountTableRows()
            }
        }, [rawData])

I've been getting this error:

Unhandled Runtime Error TypeError: Cannot add property 0, object is not extensible

Source pages\dashboard\dashboard.js (124:22) @ eval

>   122 |             item["isCoupon"]   123 |         )
> > 124 |         usersList.push(user)
>       |                  ^   125 |     })   126 |     setIsListMounted(true)   127 | } 

Call Stack mountTableRows

pages\dashboard\dashboard.js (107:16) eval pages\dashboard\dashboard.js (131:12)

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I found the problem.

I was trying to push into an state without using the setState function

 usersList.push(user)

So i read my code again and noticed my stupidity haha To fix the issue i just replaced the code above with this one below

setUsersList(current=>[...current, user])
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