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?
I've been a professional C, Perl, PHP and Python developer.
I'm an ex-sysadmin from the late 20th century.
These days I do more Javascript and CSS and whatnot, and promote UX and accessibility.
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?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" :)
Thanks, @moopet! Complete misread on my behalf! 😅