React - conditional rendering of functions and JSX

0 votes
16 views
added Apr 4 in React by lcjr First Warrant Officer (11,850 points)
// 1) Conditional rendering for function
let calc_mobileCtr = "calc_mobileCtr";

  if (isSponsorCalculator) {
    if (PropertyPrice >= 1500000) {
      calc_mobileCtr = "calc_mobileCtr hsbc";
    } else {
      calc_mobileCtr = "calc_mobileCtr";
    }
  } else {
    calc_mobileCtr = "calc_mobileCtr";
  }


// 2) Conditional rendering for JSX
  {isSponsorCalculator ? (
      PropertyPrice >= 1500000 ? (
        // show A, with function conditional rendering
        {calc_mobileCtr}
      ) : (
        // show B
      )
  ) : (
    // else, show B
  )}

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...