【发布时间】:2019-10-02 19:20:50
【问题描述】:
我正在开发一个 react redux 应用程序。我有像
这样的状态对象const initialState = {
articles: []
};
“文章”中的每个项目都像
{
id:1,
data:'data'
}
我需要在不移除数组中现有对象的情况下向数组中添加另一个对象。
我试过了
return {...state,articles: [...state.articles] };
在我的减速器中,但它最终会删除现有项目。
应该怎样才能不删除现有项目?
【问题讨论】:
-
请提供
return之前的代码。我很好奇你的声明it ends up removing the existing items.。如果这是真的,就像说state.articles发生了变异。