Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply 62 React and Next.js performance optimization rules from Vercel Engineering
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
rules/rendering-conditional-render.md
1---2title: Use Explicit Conditional Rendering3impact: LOW4impactDescription: prevents rendering 0 or NaN5tags: rendering, conditional, jsx, falsy-values6---78## Use Explicit Conditional Rendering910Use explicit ternary operators (`? :`) instead of `&&` for conditional rendering when the condition can be `0`, `NaN`, or other falsy values that render.1112**Incorrect (renders "0" when count is 0):**1314```tsx15function Badge({ count }: { count: number }) {16return (17<div>18{count && <span className="badge">{count}</span>}19</div>20)21}2223// When count = 0, renders: <div>0</div>24// When count = 5, renders: <div><span class="badge">5</span></div>25```2627**Correct (renders nothing when count is 0):**2829```tsx30function Badge({ count }: { count: number }) {31return (32<div>33{count > 0 ? <span className="badge">{count}</span> : null}34</div>35)36}3738// When count = 0, renders: <div></div>39// When count = 5, renders: <div><span class="badge">5</span></div>40```41