React by Patrik

Conditional (ternary) Operator (? :)

The conditional (ternary) operator is the only JavaScript operator that takes three operands. This operator is frequently used as a shortcut for the if statement.

Syntax: {cond ? <A /> : <B />} means “if cond, render <A />, otherwise <B />.

Sample

{itemCollapsed ? (
   <CommandItem title='Expand' />
 ) : (
   <CommandItem title='Collapse' />
 )}

Comments

Leave a Comment

All fields are required. Your email address will not be published.