I have a code like this:
type State = {
...
PromotionIDs: Number[];
autoAdjustUsage: AutoAdjustUsage[]
};
const InitState: State = {
...
PromotionIDs: [],
autoAdjustUsage: []
};
const contracts = this.state[PointsTableType.ELIGIBLE].contracts;
let result = this.state.PromotionIDs.map(i=>Number(i));
const autoAdjustPayload = {
promotionIDs: result,
usageYears: contracts.map(x => ({ usageYearId: x.usageId, applied: x.appliedPoints,usageType:x.usageType }))
};
console.log("this.state.PromotionIDs: ", this.state.PromotionIDs)
I'm not getting back any number when I console.log PromotionID. Does anyone know how can I fix this?
CodePudding user response:
To have that value in state you have to update the state.
Something like this should work.
...
let result = this.state.PromotionIDs.map(i=>Number(i));
this.setState({ PromotionIDs: result });
...