rendering-conditional-render — Claude Code rule
The rendering-conditional-render rule prevents accidental rendering of zeros and NaN in JSX. It enforces explicit ternary operators instead of && checks, so falsy values stay out of the DOM.
MIT ★ 7,191 updated 2026-10-24
.claude/rules/rendering-conditional-render.mdWhat rendering-conditional-render does
In React, count && <Badge>{count}</Badge> looks clean but breaks when count is zero—the number renders as text. The rule requires an explicit check: count > 0 ? <Badge>{count}</Badge> : null. This applies to any numeric or boolean value that could be falsy yet meaningful to your logic.
The rule activates in Claude Code when working with JSX. It scans for && patterns in conditional rendering and suggests rewriting with a ternary operator that explicitly returns null or false.
What it helps with
- Stop zeros from appearing in badge and counter components
- Control conditional rendering when props hold numeric values
- Catch falsy values that should remain invisible in output
Example prompts for the agent
- See
{count && {count}}and let Claude rewrite it with a ternary - Review a Badge component that accepts a prop that might be zero
- Verify that NaN and 0 never leak into the DOM
How to install rendering-conditional-render
Manually: put the files in place
.claude/rules/rendering-conditional-render.mdThe paths frontmatter field limits the files
AGENTS.md
Codex reads AGENTS.md: paste the rule text there
Manually: put the files in place
.cursor/rules/rendering-conditional-render.mdcFrontmatter: description, globs, alwaysApply
Manually: put the files in place
.github/instructions/rendering-conditional-render.instructions.mdThe applyTo field sets which files it applies to
Manually: put the files in place
.devin/rules/rendering-conditional-render.mdManually: put the files in place
.clinerules/rendering-conditional-render.mdStep by step, with commands for each platform: AGENTS.md vs CLAUDE.md: what they are and which one to use
Questions about rendering-conditional-render
How do I install rendering-conditional-render in Claude Code?
Create .claude/rules/rendering-conditional-render.md at your project root with the rule content. Claude Code will pick it up automatically in your next session.
What does this rule do?
It catches conditional render patterns where && is used with numbers or other falsy values. It suggests switching to a ternary operator so that zero or NaN do not reach the output.
Why is count && <Badge> problematic?
The && operator returns its left operand if falsy. When count is zero, React renders the digit 0 directly into the DOM instead of the component.
Source text
rendering-conditional-render.md · MIT
---
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>
```
© tech-leads-club · MIT · tech-leads-club/agent-skills