I'm using the conditional operator to determine whether an extra element should be included in my React component. For some reason if product.rating
is 0 I see it rendered after the name. If I typecast the value to bool like Boolean(product.rating)
the 0 is gone.
My question is why the 0 is rendered at the first place, shouldn't the falsy value evaluate the condition as false?
function Product ({product}) {
return (
<div>
<h1>{product.name}</h1>
{product.rating && (
<Stars count={product.rating} />
)}
</div>
)
}