What's a compact way to write conditional statements in ReactJS? Give example?
In ReactJS we can use the Ternary operator.
Written the same in ReactJS as it does in regular JS:
x ? y : z,
When your code is executed, x is evaluated as either true or false. If x evaluates to true, then the entire ternary operator returns y. If x evaluates to false, then the entire ternary operator returns z.
Example:
var headline = (
<h1>
{ age >= MinMarrigeAge ? 'Select Girl' : 'Wait for some year' }
</h1>
);
Written the same in ReactJS as it does in regular JS:
x ? y : z,
When your code is executed, x is evaluated as either true or false. If x evaluates to true, then the entire ternary operator returns y. If x evaluates to false, then the entire ternary operator returns z.
Example:
var headline = (
<h1>
{ age >= MinMarrigeAge ? 'Select Girl' : 'Wait for some year' }
</h1>
);
Comments