DEV Community

Discussion on: Cleaner React: Conditional Rendering

Collapse
 
johnsoncherian profile image
Johnson • Edited

The code below will render "0" when data is empty.
const RenderData = ({ data }) => data.length && data.map(...);

What about this.?
const RenderData = ({ data }) => (!!data.length) && data.map(...);

Collapse
 
sturdynut profile image
Matti Salokangas

That would return false. I think the trap here is that it is easy to forget to cast the data.length to a boolean type.