rendering-conditional-render

📁 theorcdev/8bitcn-ui 📅 Jan 23, 2026
16
总安装量
12
周安装量
#21418
全站排名
安装命令
npx skills add https://github.com/theorcdev/8bitcn-ui --skill rendering-conditional-render

Agent 安装分布

claude-code 9
opencode 8
codex 8
windsurf 8
gemini-cli 7
antigravity 7

Skill 文档

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>