DEV Community

Discussion on: 4 Ways to Render JSX Conditionally in React

Collapse
 
danwalsh profile image
Dan Walsh • Edited

In this extremely limited example, I’d agree that boiling the component down to a single ternary is fine. Most real world components however will contain more than a single truthy test and a single line of JSX in their return.

Guard clauses (or early returns) are great for refactoring nested conditional trees. Should you use them for every component? No. Does it meet the author’s post criteria of “Ways to Render JSX Conditionally in React”? Yes, I’d say so.

I’m not familiar with “scrape returns”, and I can’t seem to find any examples online. Can you elaborate, please?

Thread Thread
 
moopet profile image
Ben Sinclair

They said, "scape" not "scrape" so I'm assuming it's either a typo for "Escape" or slang for it.

I can see how "escape" could sound a bit cooler than "return early" :)

Thread Thread
 
danwalsh profile image
Dan Walsh

Thanks, @moopet! Complete misread on my behalf! 😅