[英]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.