React - conditional rendering for JSX

0 votes
170 views
added Apr 3 in React by lcjr First Warrant Officer (11,970 points)
{isSponsorCalculator ? (
    PropertyPrice >= 1500000 ? (
        // Do this if PropertyPrice is greater than or equal to 1500000
        <p>Do this</p>
    ) : (
        // Do this if PropertyPrice is less than 1500000
        <p>Do something else</p>
    )
) : (
    // Do this if isSponsorCalculator is false
    <p>Else this</p>
)}

In this code:

  • isSponsorCalculator is the condition that determines which block of code to execute.
  • PropertyPrice >= 1500000 is another condition nested inside the first one. If it's true, the first block executes; otherwise, the second block executes.
  • Inside each block, there are JSX elements (<p>...</p>) representing what should be rendered in that condition. You can replace these with your actual code.

Make sure to adjust the JSX elements and conditions to match your specific use case.

1 Response

0 votes
responded Apr 3 by lcjr First Warrant Officer (11,970 points)
{isSponsorCalculator ? (
    PropertyPrice >= 1500000 ? (
      <img
      className={calc_sideImgBg}
      src="/brands/calc/abc_bg2.png"
      onClick={abcClick}
      alt="Mortgage-calculator"
    />
    ) : (
      <img
        className={calc_sideImgBg}
        onClick={mortgageclick}
        src="/static/images/mortgage-calc/mortgage-bg.png"
        alt="Mortgage-calculator"
      />
    )
) : (
  <img
    className={calc_sideImgBg}
    onClick={mortgageclick}
    src="/static/images/mortgage-calc/mortgage-bg.png"
    alt="Mortgage-calculator"
  />
)}

 

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