[英]push new array of object into existing array of object using spread of ES6
這種語法甚至正確嗎? 結果是我的對象數組,它是嵌套的。
notifications: {
...state.notifications,
results: [
...state.notifications.results,
{ ...state.notifications.results }
]
}
這應該是可行的。
notifications: {
...state.notifications,
results: [
...state.notifications.results
]
}
在我看來,您正在嘗試運行this.setState
並同時更新數組。
完整的命令將如下所示:
this.setState({
notifications: {
...this.state.notifications,
results: [
...this.state.results,
// whatever you're trying to add goes here
]
}
});
我只是根據您問題的標簽進行猜測。 請隨時發表評論並進一步說明您的情況,以便我調整答案以更好地適合您的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.