- Forums
- ionic
- IONIC REACT - Example of Conditional IF ELSE Condition In TSX Code
this is an example how to implement an if/else conditional statement in react ionic app [4972], Last Updated: Mon Jun 24, 2024
edwin
Sun Jan 16, 2022
0 Comments
1755 Visits
To implement IF/ELSE conditional statement within the IONIC HTML code not in the Javascript code, this is how you do it.
for example
const showBlue:boolean = true;
return (
{
showBlue ? (
<message>Blue</message>
) : (
<message>Red</message>
)
}
)
In this simple example, we are using a ternary conditional statement.
The varilable showBlue has a value of true, therefore, the Blue message will be shown in the IONIC REACT code.