Redux 使用数组将推送到第二级对象
我有一个redux商店,看起来像这样:Redux 使用数组将推送到第二级对象,redux,immutable.js,Redux,Immutable.js,我有一个redux商店,看起来像这样: posts : { posts: [ 0: { }, 1: { } ] } case LOAD_MORE_POSTS_SUCCESS: return { ...state, posts: [...state.posts, action.posts], isFetching: false, } case LOAD_MORE_POSTS_SUCCESS: return { ..
posts : {
posts: [
0: { },
1: { }
]
}
case LOAD_MORE_POSTS_SUCCESS:
return {
...state,
posts: [...state.posts, action.posts],
isFetching: false,
}
case LOAD_MORE_POSTS_SUCCESS:
return {
...state,
posts: [...state.posts, ...action.posts],
isFetching: false,
}
我想在数组中添加以下额外项:
posts : {
posts: [
0: { },
1: { }
]
}
case LOAD_MORE_POSTS_SUCCESS:
return {
...state,
posts: [...state.posts, action.posts],
isFetching: false,
}
case LOAD_MORE_POSTS_SUCCESS:
return {
...state,
posts: [...state.posts, ...action.posts],
isFetching: false,
}
然而,这只是把额外的职位推到了第一级,我尝试过这样做(运气不好):
你有没有试过这样的方法:
case LOAD_MORE_POSTS_SUCCESS:
return {
...state,
posts: {
posts: [...state.posts.posts, action.posts]
},
isFetching: false,
}
和如果<代码> Actudio。POST <代码>是一个数组(复数形式暗示它是),考虑使用:
posts: {
posts: [...state.posts.posts, ...action.posts]
}
感谢@Gila Artzi-我的最终代码如下所示:
posts : {
posts: [
0: { },
1: { }
]
}
case LOAD_MORE_POSTS_SUCCESS:
return {
...state,
posts: [...state.posts, action.posts],
isFetching: false,
}
case LOAD_MORE_POSTS_SUCCESS:
return {
...state,
posts: [...state.posts, ...action.posts],
isFetching: false,
}
非常感谢-我需要包括操作的spread操作符:…action.posts。