我得到:
TypeError:无法读取未定义的属性'concat'”
但是,我已经在initialState
中定义了'orders'数组。
有人知道原因吗?
const initialState = {
orders: [],
loading: false,
purchased: false
};
const purchaseBurgerSuccess = (state, action) => {
const newOrder = updateObject(action.orderData, { id: action.orderId });
return updateObject(state,
{
loading: false,
purchased: true,
orders: state.orders.concat(newOrder)
});
};
[不确定为什么再次使用updateObject
。您的退货应该看起来像这样...
return {
...state,
loading: false,
purchased: true,
orders: state.orders.concat(newOrder)
};
...分散状态并更新所需属性的位置。