--- title: Use Explicit Conditional Rendering impact: LOW impactDescription: prevents rendering 0 or NaN tags: rendering, conditional, jsx, falsy-values --- ## Use Explicit Conditional Rendering Use explicit ternary operators (`? :`) instead of `&&` for conditional rendering when the condition can be `0`, `NaN`, or other falsy values that render. **Incorrect (renders "0" when count is 0):** ```tsx function Badge({ count }: { count: number }) { return (
{count && {count}}
) } // When count = 0, renders:
0
// When count = 5, renders:
5
``` **Correct (renders nothing when count is 0):** ```tsx function Badge({ count }: { count: number }) { return (
{count > 0 ? {count} : null}
) } // When count = 0, renders:
// When count = 5, renders:
5
```