Wednesday, 1 February 2017

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>
);


WHAT OTHERS ARE READING/RELATED TO THIS:

0 comments:

Post a Comment

Find job here...