-1

The below code is written inside a function in react Model class(MVC Architecture). Every time the function is called the temp variable value is set to 1 but I want the value of the updated temp variable to be assigned to the 1st line. Please help

                 var temp = 1;
                console.log("temp = "+temp)
                let sPlanId = constant['SUBSCRIPTION_TIERS'][event_subscription.plan_id];
                console.log("SPlanId = "+sPlanId)
                if(sPlanId-temp == 1 && sPlanId == 2)
                {
                    fix_project_post_cnt = 4;
                    temp = sPlanId;
                }
                else if(sPlanId-temp == 1 && sPlanId == 3)
                {
                    fix_project_post_cnt = 5;
                    temp = sPlanId;
                }
                else if(sPlanId-temp == 2 && sPlanId == 3)
                {
                    fix_project_post_cnt = 9;
                    temp = sPlanId;
                }
                else if(sPlanId-temp == 1 && sPlanId == 4)
                {
                    fix_project_post_cnt = 10;
                    temp = sPlanId;
                }
                else if(sPlanId-temp == 2 && sPlanId == 4)
                {
                    fix_project_post_cnt = 15;
                    temp = sPlanId;
                }
                else if(sPlanId-temp == 3 && sPlanId == 4)
                {
                    fix_project_post_cnt = 19;
                    temp = sPlanId;
                }
  • Not sure I understand your desired result, what are you trying to achieve? – Itay Ganor Sep 03 '21 at 10:51
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Sep 07 '21 at 09:23

1 Answers1

0

I am going to assume it's a react functional component, since code is unclear. you can useEffect hook and this temp variable as a dependency.

  • It is neither a functional component nor a class component. This function is written inside a model class where all the API call functions are defined. All I need to do is that the value of temp that comes at the end of if-else execution need to be updated instead of 1(Var temp = 1) so that the next time this function is called the value of temp is the one which was updated. – pankaj verma Sep 03 '21 at 11:48