DEV Community

Discussion on: React Clean Code - Simple ways to write better and cleaner code

Collapse
 
joaorafaelsantos profile image
João Santos

I agree. I've been refactoring several React components lately, and ternary operators (in my opinion) make the code noisy.

While two separate conditionals may indicate these pieces are not related, I think it's easier to read and understand.

Collapse
 
mrchedda profile image
mr chedda

Writing two separate conditionals for conditionally rendering two components, is inefficient not to mention rudimentary programming. Ternary syntax is much more concise and expected from a dev working in a production application IMHO. Imagine a switch statement writing the same n case statements for 1 result instead of using fall through. It may be more “readable” in terms of leisure reading but not pragmatic programming in any way.