it keeps looping and resetting back to the default date.
Does `default date mean the date one month after the startOn date?
I'm a bit confused by the question and would like clarification. Based on your code, I assume the flow would then be:
API Response -> setPaymentData(data) -> User manually updates renew date -> Reset back to old value
I saw you checking the condition of data.results.paymentSummary.startOn && data.results.paymentSummary.renewOn
, as well as data.results.paymentSummary.startOn
individually, but did not see you check when data only has renewOn
, are you missing that case or is it intentional?
Maybe adding case where data.results.paymentSummary.renewOn
is not null and add logic there will solve the problem?
else if(data.results.paymentSummary.renewOn) {
renewOn = localIsoString(data.results.paymentSummary.renewOn).slice(0,10); // Keep startOn the same
}
Also sorry for my two cent, but I think your code is mixing between snake_case
and camelCase
for property names which is not an ideal way to code JS, better keep it consistent by using camelCase, snake_case are mostly used for naming variable.