Kent C. Dodds 7/1/2020

Use ternaries rather than && in JSX

Read Original

This article details a common React/JSX pitfall: using the && operator for conditional rendering can unintentionally render values like 0 or cause errors when returning undefined. The author, citing a real-world example from PayPal, demonstrates how using ternary operators (condition ? result : null) provides explicit control over what renders in both truthy and falsy cases, preventing these bugs.

Use ternaries rather than && in JSX

Comments

No comments yet

Be the first to share your thoughts!

Browser Extension

Get instant access to AllDevBlogs from your browser

Top of the Week

No top articles yet