texi rv texi rv - 2 months ago 9
React JSX Question

the value of sports.tickets.goalValues is 0, I should not display any p tag

-when the value of sports.tickets.goalValues is 0, I should not display any p tag. - but now if its 0 its displays the second p tag with value 0 in it.It goes inside
else condition
- can you guys tell me how to fix it.
- providing snippet of code below.

< th className = "highlighted-amount" >
< strong > tickets < /strong> {
sports.summary.error || isNaN(sports.tickets.goalValues) ?
< p className = "sports-running-again" > sports value with popcorn Unavailable < /p> : < p className = "sports-running-again" > sports value with popcorn {
moneyFormat(sports.tickets.goalValues)
} < /p>
}

< /th>

Answer

In such a case you should make use of the if-elseif-else condition istead of a ternary operator like

var comp = null;
if(sports.summary.error || isNaN(sports.tickets.goalValues)) {
  comp = < p className = "sports-running-again" > sports value with popcorn Unavailable < /p> ;

}
else if(!isNaN(sports.tickets.goalValues) && sports.tickets.goalValues == 0) {
  comp = null;
}
else {
  comp = < p className = "sports-running-again" > sports value with popcorn {
        moneyFormat(sports.tickets.goalValues)
      } < /p>
}

< th className = "highlighted-amount" >
  < strong > tickets < /strong> { comp }

< /th>