【发布时间】:2019-04-06 20:15:48
【问题描述】:
我有一个关于嵌套减速器的问题。
结构类似这样:
const INITIAL_STATE = {
items: [],
planningState:null,
loading: false,
idx_selected : '2'
};
在 state.items 中,结构是这样的:
const mockItems = [
{
date: "2018-08-24 15:00:00",
type: "dropoff",
status: null,
id: "553",
//many others things
},
{
date: "2018-08-24 19:00:00",
type: "pickup",
status: "ordered",
id: "553",
//other things
},
{
date: "2018-07-18 08:00:00",
type: "delivery",
status: null,
id: "554",
//other things
},
];
我需要更改一项的状态,而不更改其他属性。我知道我必须克隆每一层,但我犯了一个错误。
case SCAN_CLOSE_DONE:
//state.items[state.idx_selected].status=done
return{
...state,
items:{
...state.items,
[state.idx_selected]:{
...state.items[state.idx_selected],
status: "done"
}
}
};
【问题讨论】:
标签: react-native redux nested reducers