I have a React class based component with a nested component that handles a state update given as assignAccountsValue. The issue is, when I change spouses, the selectedAccounts is the same for both spouses, so selecting one spouses’ accounts updates the other spouses’ too.
const initRegularField =
activeSpouse === 'spouse' ? 'initRegular' : 'initRegular2';
const initRegularFromAccField =
activeSpouse === 'spouse' ? 'initRegularFromAcc' : 'initRegularFromAcc2';
const initRegAccListField =
activeSpouse === 'spouse' ? 'initRegAccList' : 'initRegAccList2';
const initRRIFFromAccField =
activeSpouse === 'spouse' ? 'initRRIFFromAcc' : 'initRRIFFromAcc2';
<AccountsDropdown
inputs={inputs}
error={errors[initRegularField]}
accountList={accountList}
selectedAccList={inputs[initRegAccListField]}
excludedList={excludedList}
savedAccountsValue={inputs[initRegularField] || 0}
assignAccountsValue={(selectedAccounts, accountsValue) => {
this.props.dispatch(
Planning.drawdownUpdateInput({
inputs: {
[initRegAccListField]: selectedAccounts,
[initRegularField]: accountsValue,
},
errors: { [initRegularField]: false },
modified: true,
})
);
}}
float
/>