Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Next.js and React

A boolean written in JSX shows nothing on the page

Your error

<p>Admin: {isAdmin}</p> shows only the label, with no true or false after it2 more lines it can show

Fix it fast

Most common cause, 1 of 2

A boolean is placed directly in the JSX

Decide what the reader should see and build that text yourself.

Fix
<p>Admin: {isAdmin ? 'Yes' : 'No'}</p>
<p>Active: {String(isActive)}</p>
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

A boolean in JSX such as {isAdmin} shows nothing because React 19 treats true, false, null and undefined as empty nodes. Turn the value into text yourself with a ternary or String(isAdmin). The opposite trap is a count of 0 on the left of &&: a number, not a boolean, so React prints the 0.

  • Applies to React 19.3, Next.js 16.4, Vite 8.3
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Show the real values and their types on the page, next to the place that renders wrongly. JSON.stringify keeps true, 0 and the string "true" visibly different.

Run this first
<pre>{JSON.stringify({ isAdmin, count })}</pre>

Then find the line you see in this list and open its fix:

  1. 1A boolean is placed directly in the JSXThe JSON output shows true or false, and the screen shows nothing at that spot
  2. 2A number sits on the left of &&A stray 0 appears exactly when the list or counter is empty

What does the error look like?

  • <p>Admin: {isAdmin}</p> shows only the label, with no true or false after it
  • A block that should be hidden shows a lone 0 instead
  • Strings and numbers inside braces appear on the page, true and false never do

Cause 1 of 2

A boolean is placed directly in the JSX

You seeThe JSON output shows true or false, and the screen shows nothing at that spot

Check

A boolean placed straight into JSX renders nothing because React counts it as an empty node. React's docs list null, undefined and booleans that way among the valid values for children. They are accepted as content and they draw nothing, so {isAdmin} is not a bug in React but a value with no visible form.

Check
grep -rn -E "\{(is|has|can|should)[A-Za-z]*\}" src

Fix

Decide what the reader should see and build that text yourself. A ternary picks one of two strings, and String() prints the word.

Fix
<p>Admin: {isAdmin ? 'Yes' : 'No'}</p>
<p>Active: {String(isActive)}</p>

Verify

Reload the page and check that the text now follows the value.

Verify
npm run dev

Confirmed by react.dev

Did this fix it?

Cause 2 of 2

A number sits on the left of &&

You seeA stray 0 appears exactly when the list or counter is empty

Check

A stray 0 on the page comes from a number on the left of &&, which React renders like any other number. The expression count && <Badge /> returns the left side when it is falsy. With a count of 0 that value is the number 0. With a real false, React leaves a hole in the tree and renders nothing.

Check
grep -rn -E "\.length &&|[Cc]ount &&" src

Fix

Make the left side a boolean with a comparison, or use a ternary that returns null for the empty case.

Fix
{items.length > 0 && <List items={items} />}

{items.length ? <List items={items} /> : null}

Verify

Load the page with an empty list. Nothing appears where the 0 used to be.

Verify
npm run dev

Confirmed by react.dev

Did this fix it?

How do I stop it coming back?

  • Write conditions as comparisons (items.length > 0, count !== 0) so the left side of && is always a true boolean.
  • Keep one small helper for yes/no text instead of repeating ternaries across components.
  • When a flag has to be visible while debugging, print it with JSON.stringify rather than relying on JSX to show it.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: TaxiDex, QistLock, Taskvare.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.