DEV Community

Discussion on: 30 JavaScript Tricky Hacks

Collapse
 
seandinan profile image
Sean Dinan • Edited

As a counter-point for short circuit evaluation, I've mostly switched over to it for conditionally rendering things in JSX. I stuck to ternary for years but have gradually switched over.

I'd now say that:

return (
  <section>
    {isLoading && <LoadingMessage/>}
    {/* ... */}
  </section>
)
Enter fullscreen mode Exit fullscreen mode

is at least as clear as:

return (
  <section>
    {isLoading ? <LoadingMessage/> : null}
    {/* ... */}
  </section>
)
Enter fullscreen mode Exit fullscreen mode
Collapse
 
moopet profile image
Ben Sinclair

I agree, for things like JSX (which still look uncomfortable to me even after a few years) it is still readable - provided you keep things simple.