React by Patrik

Logical && Operator

In React it often comes up when you want to render some JSX when the condition is true, or render nothing otherwise. 

Syntax: {cond && <A />} means “if cond, render <A />, otherwise nothing”.

Sample

{article.content.length > 0 && (
   <ArticleContent content={article.content} slug={article.slug} />
)

Comments

Leave a Comment

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