Skills included: - pr-reviewer: Adapted for Gitea/GitHub via platform-aware scripts (dropped fetch_pr_data.py and add_inline_comment.py, kept generate_review_files.py) - code-review-excellence: Methodology and checklists (React, TS, Python, etc.) - vercel-react-best-practices: 57 rules for React/Next.js performance - tailwind-design-system: Tailwind CSS v4 patterns, CVA, design tokens New shell scripts added to ~/.claude/scripts/git/: - pr-diff.sh: Get PR diff (GitHub gh / Gitea API) - pr-metadata.sh: Get PR metadata as normalized JSON Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
41 lines
980 B
Markdown
41 lines
980 B
Markdown
---
|
|
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 (
|
|
<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>
|
|
```
|