这是该函数中涉及的代码,目标是创建用于在Material Ui表中呈现的行。
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])
我已经得到这个错误:
未处理的运行时错误类型错误:不能添加属性0,对象是没有可扩展的
源页面dashboarddashboard.js (124:22) @ eval
> 122 | item["isCoupon"] 123 | )
> > 124 | usersList.push(user)
> | ^ 125 | }) 126 | setIsListMounted(true) 127 | }
调用栈mountTableRows
pagesdashboarddashboard.js (107:16页面 dashboard dashboard.js (131:12)
我找到问题了。
我试图在不使用setState函数的情况下进入一个状态
usersList.push(user)
所以我再次阅读我的代码,发现我的愚蠢哈哈为了解决这个问题,我只是用
下面的代码替换了上面的代码setUsersList(current=>[...current, user])