DEV Community

Discussion on: 4 Ways to Render JSX Conditionally in React

Collapse
 
miketalbot profile image
Mike Talbot ⭐ • Edited

Or even:

    const MyComponent = ({name})=>!!name && 
         <p>Hi! My name is {name}.</p>;
Enter fullscreen mode Exit fullscreen mode

Though I definitely think ternaries are easier to comprehend if you aren't used to looking at that kind of logic

Thread Thread
 
moopet profile image
Ben Sinclair

Cramming everything you possibly can on to one line is definitely something I see a lot in Javascript, but I think it's a weird and ultimately self-destructive style.

There's no penaltly in terms of performance to use a little vertical space, and I much prefer comfortable reading instead of horizontal scrollbars or weird line-wrapping.