And why one is better than the other?
do-expressions are also useful for this. There is a babel-plugin for this.
Nothing wrong with either way but React's docs even point to use the && operator for conditional 'if' rendering.
facebook.github.io/react/docs/conditional-renderi…
and it's less code!
Sai Kishore Komanduri
Engineering an eGovernance Product | Hashnode Alumnus | I love pixel art
I would say the second one, because short-circuit evaluation is awesome; it helps you write concise, bloat-free code.
Short-cut what? 💁
I'll let Wikipedia do the talking:
This holds true even in JS:
conditional && expression,expressionisn't evaluated unless theconditionalistrue.conditional || expression,expressionisn't evaluated unless theconditionalisfalse.