Agent Skills: 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.

UncategorizedID: theorcdev/8bitcn-ui/rendering-conditional-render

Install this agent skill to your local

pnpm dlx add-skill https://github.com/TheOrcDev/8bitcn-ui/tree/HEAD/.claude/skills/rendering-conditional-render

Skill Files

Browse the full folder contents for rendering-conditional-render.

Download Skill

Loading file tree…

.claude/skills/rendering-conditional-render/SKILL.md

Skill Metadata

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):

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):

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>