Skip to main content

rendering-conditional-render

Use explicit ternary operators instead of && for conditional rendering. Apply when rendering values that could be 0, NaN, or other falsy values that might render unexpectedly.

Source facts

Repository
TheOrcDev/8bitcn-ui
Last source activity
January 16, 2026 at 09:09
Detected SKILL.md language
English
Stars
2,061
Forks
119

Install options

The review-first prompt is selected by default. You can switch to a direct command or download a local copy.

Review the source files

Read SKILL.md and any companion files shown by SkillsMP before deciding whether to install.

Showing SKILL.md

SKILL.md
Source instructions · Read-only preview
name
rendering-conditional-render
description
Use explicit ternary operators instead of && for conditional rendering. Apply when rendering values that could be 0, NaN, or other falsy values that might render unexpectedly.
## 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 ( <div> {count && <span className="badge">{count}</span>} </div> ) } // When count = 0, renders: <div>0</div> // When count = 5, renders: <div><span class="badge">5</span></div> ``` **Correct (renders nothing when count is 0):** ```tsx function Badge({ count }: { count: number }) { return ( <div> {count > 0 ? <span className="badge">{count}</span> : null} </div> ) } // When count = 0, renders: <div></div> // When count = 5, renders: <div><span class="badge">5</span></div> ```
View on GitHub