Why React Shows 0 with && Conditional Rendering and How to Fix It
When you write {count && <p>…</p>} in React, "0" appears where nothing should be shown when count is 0. The && operator returns the left-hand 0 as is, and React renders the number 0 as text. Making the left side an expression that evaluates to true or false, such as {count > 0 && <p>…</p>}, fixes it. This mistake often happens when switching the display for an unread-count badge, a search result count, or whether a list is empty. The official documentation also lists it as a common mistake.
The test environment was Ubuntu 24.04 with Node.js 22.23.4. I used a project created from the react-ts template of npm create vite@latest (react / react-dom 19.3.1, Vite 8.3.8, TypeScript 7.0.2, oxlint 1.93.0), and wrapped the components in StrictMode. I opened the pages on the development server and checked the display by operating Chromium 153 with Playwright 1.63.0. I did not test React Native or browsers other than Chromium.
When there are no unread items, only "0" appears under the heading
I prepared the following two components. The first shows a message only when there are unread items. The second shows a list only when the to-do list is not empty.
// Wrong: when count is 0, the 0 on the left of && is displayed as is
type Props = { count: number };
export default function UnreadBadge({ count }: Props) {
return (
<div>
<h2>受信箱</h2>
{count && <p>未読が {count} 件あります</p>}
</div>
);
}
// Wrong: when the array is empty, the 0 from items.length is displayed
type Props = { items: string[] };
export default function TodoList({ items }: Props) {
return (
<div>
<h2>やること</h2>
{items.length && (
<ul>
{items.map((item) => (
<li key={item}>{item}</li>
))}
</ul>
)}
</div>
);
}
When I opened <UnreadBadge count={0} /> and <TodoList items={[]} /> on the development server, "0" appeared under both headings.

I checked the page contents. Neither <p> nor <ul> was created. Only the text 0 was inside the <div>.
<div><h2>受信箱</h2>0</div><div><h2>やること</h2>0</div>
No warnings or errors appeared in the browser console. A number is a value React can render, so React does not warn. In addition, when I passed the same components with count={3} and items={['ごはん', 'おやつ']} through renderToString, the message saying there are 3 unread items and a two-item list were rendered as expected. The output looks correct when there are items, so this mistake is easy to miss until you check the zero-count case on screen.
&& returns the left-hand value when the left side is falsy
As the MDN explanation of the logical AND operator (&&) describes, a && b returns a itself if a is a falsy value, and otherwise returns b. It is not an operator that returns true or false. Because 0 is falsy, count && <p>…</p> evaluates to 0, not false, when count is 0.
On the other hand, React renders nothing for false, null, and undefined (and also for true). The official documentation on conditional rendering also states that false renders nothing, just like null or undefined. A number is one of the values React can render (React nodes), so 0 is shown as text. The same section of the official documentation also warns not to put a number on the left side of &&.
For each value placed on the left side, I checked what <div>{value && <p>display</p>}</div> produces with renderToString.
Left side of && |
What was displayed |
|---|---|
0 |
0 |
-0 |
0 |
0n (BigInt 0) |
0 |
NaN |
NaN |
'' (empty string) |
Nothing |
false, null, undefined |
Nothing |
0 > 0, !!0, Boolean(0) |
Nothing |
Among the falsy values, the number 0, -0, NaN, and the BigInt 0n were displayed as text. For NaN, the warning Received NaN for the `children` attribute. also appeared. An empty string is falsy so the left side is returned, but since it is an empty string, nothing appears on screen.
Fix it by making the left side true / false
Change the left side to an expression that evaluates to true or false. For a count, comparing whether it is greater than 0 is easy to read.
// Fixed: the left side of && is now a true / false result of a comparison
type Props = { count: number };
export default function UnreadBadgeFixed({ count }: Props) {
return (
<div>
<h2>受信箱</h2>
{count > 0 && <p>未読が {count} 件あります</p>}
</div>
);
}
As the table above shows, writing !!count or Boolean(count) also prevents 0 from appearing. However, count > 0 makes the intent, "when the count is 1 or more," clear from the code.
If you want to show a message such as "There is nothing to do" when the list is empty, use a ternary operator instead of &&, and write the content for the empty case too.
// Fixed: choose what to show when empty with a ternary operator
type Props = { items: string[] };
export default function TodoListFixed({ items }: Props) {
return (
<div>
<h2>やること</h2>
{items.length > 0 ? (
<ul>
{items.map((item) => (
<li key={item}>{item}</li>
))}
</ul>
) : (
<p>やることはありません</p>
)}
</div>
);
}
When I opened it again with count={0} and items={[]}, nothing appeared under the Inbox heading, and the message "There is nothing to do" appeared under the To-do heading.

The type check and lint from the template do not catch it
Running npx tsc -p tsconfig.app.json --noEmit on the code with the mistake produced no errors. The type of count && <p>…</p> is "a number or a JSX element," and both are included in the { } JSX child type (ReactNode) defined in @types/react 19.3.0, which was used in the test environment. oxlint, which is included in the template, also reported nothing when I ran npx oxlint src with the default configuration.
With the template's settings, the type check and lint both pass, and nothing appears in the console, so you will not notice until you look at the page. For any && whose left side is a count or a length, either check the screen with zero items, or write > 0 from the start to be safe.





