Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I'm not getting back number in react typescript

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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 });
...
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading