【发布时间】:2019-07-27 01:07:53
【问题描述】:
我有一个 reducer 状态初始化如下:
state = {
name: ""
authenticationObj: {
userContactInfo: {
billingAddress: {
billingCountry: undefined,
billingAddress1: undefined,
billingAddress2: undefined,
billingCity: undefined,
billingPostalCode: undefined,
billingPhoneNumber: undefined,
billingFirstName: undefined,
billingLastName: undefined,
billingPersonalEmail: undefined,
billingSelectedRegion: undefined
},
},
subscriptions: [],
fullName: "",
subscriberDefaultPhoneNumber: ""
}
}
现在我需要使用扩展运算符来更新状态,这就是我所拥有的:
case SET_SUBSC_LIST:
state = { ...state,
authenticationObj: { ...state.authenticationObj,
subscriptions: action.payload.subscriptions
}
}
但是如果我想更新不同级别的属性怎么办。例如,如果我需要同时更新订阅以及 billingAddress1 中的 billingAddress1,我该如何实现?
【问题讨论】:
-
您不使用
setState的任何原因? -
@samb102 我需要使用redux
标签: javascript reactjs ecmascript-6 redux