DEV Community

Discussion on: How to write if statement in React.js?

Collapse
duomly profile image
Duomly Author

Good point!

Actually I'd do it another way than his ideas, and his conditional rendering can produce a problem, not because conditional rendering, but because of the way how conditional rendering is used there.

I think to render anything shouldn't happen at all if there is no data.
In most cases, he should check if the length is bigger than zero to render even a container, not render even ul element, but show some msg about no items.

I'm a big fan of the ternary operator, but it's a good idea in some cases, definitely shouldn't be used as a fix for every case.