DEV Community

Cover image for Working with conditions & lists in React

Working with conditions & lists in React

Sergio Daniel Xalambrí on June 18, 2019

In a previous article I wrote about how to start a React project using the state and effect hooks, this time we will see how to work with condition...
Collapse
 
gustavofsantos profile image
Gustavo Santos

Particularly I'd avoid using ternary inside jsx. It scales very well and soon your components will be full of ternaries and the mess will be everywhere

Collapse
 
chibiblasphem profile image
Debove Christopher

What do you advise to use then ? Ternary is expression and inside jsx expressions are the only way to do condition

Btw don't tell me to create a function which do the condition, that's really dirty. Well coded the use of ternary does not turn your code a mess.

Note that this is only my opinion

Collapse
 
sergiodxa profile image
Sergio Daniel Xalambrí

I think if you reach the point of having a lot of ternaries or too much nested ternaries, maybe, that component should be split in multiple components because the original one becomes too complex.

But most of the time ternaries are not a problem IMO and you can use them without issues, most probably before you reach the point ternaries are a problem you have another problem and already split the component.