TypeError:无法读取ReactJs中未定义的属性'concat'

问题描述 投票:0回答:1

我得到:

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)
    });
};
javascript reactjs redux reducers
1个回答
0
投票

[不确定为什么再次使用updateObject。您的退货应该看起来像这样...

return {
  ...state,
  loading: false,
  purchased: true,
  orders: state.orders.concat(newOrder)
};

...分散状态并更新所需属性的位置。

© www.soinside.com 2019 - 2024. All rights reserved.