Maaz Zindani

Loading the index…

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

React warns that text cannot appear as a child of a table row

ErrorIn HTML, text nodes cannot be a child of <tr>. This will cause a hydration error.

Short answer

A tr may contain only td and th elements (and script-supporting elements). The warning means a piece of text sits directly in a row: a typed word, a string, a number or a {' '} between the cells. Wrap it in a td, or remove it. Check any expression that can return plain text.

  • Applies to React 19, Next.js 15
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    The warning prints a component stack. Take the first component under tr and look in its JSX for anything that is not a td or th.

    grep -rn -A6 "<tr" src/ | grep -v "<td\|<th\|</t"
  2. 2Match what you see, then jump to its fix

    1. 1A literal word, or {' '}, sits between two td elementsText or a space is written between the cellsFix
    2. 2{count}, {label} or {cond && 'text'} is a direct child of trAn expression in the row returns a string or numberFix
    3. 3rows.map(...) inside tr, or a map callback with { } and no returnMapped rows return text or several elements without a keyFix

What does the error look like?

  • In HTML, text nodes cannot be a child of <tr>. This will cause a hydration error.
  • In HTML, whitespace text nodes cannot be a child of <tr>.

Cause 1 of 3

Text or a space is written between the cells

1Check

The HTML standard defines the content model of tr as zero or more td, th and script-supporting elements. Text is not allowed.

grep -rn "</td>.\+<td\|{' '}\|{\" \"}" src/

2Fix

Delete the stray text or move it inside a cell.

<tr>
  <td>Name</td>
  <td>Price</td>
</tr>

3Verify

Reload: the warning is gone from the console.

npm run dev

Confirmed by raw.githubusercontent.com

Did this fix it?

Cause 2 of 3

An expression in the row returns a string or number

1Check

Anything inside braces that evaluates to a string or number becomes a text node. Placed directly under tr, it is not in a cell.

grep -rn -B1 -A1 "<tr" src/ | grep "{"

2Fix

Render the value inside a td or th.

<tr>
  <td>{label}</td>
  <td>{count}</td>
</tr>

3Verify

The row shows the values in their own cells and the console is clean.

npm run dev

Confirmed by html.spec.whatwg.org

Did this fix it?

Cause 3 of 3

Mapped rows return text or several elements without a key

1Check

An arrow function with a curly brace needs an explicit return: without it, nothing is returned. If you map cells that need a key and more than one element per item, use Fragment with a key.

grep -rn "\.map(" src/ | grep -i "tr\|td"

2Fix

Map the cells inside tr, map the rows inside tbody, and return elements.

<tbody>
  {rows.map(row => (
    <tr key={row.id}>
      <td>{row.name}</td>
      <td>{row.price}</td>
    </tr>
  ))}
</tbody>

3Verify

Each data item shows as one row.

npm run dev

Confirmed by react.dev

Did this fix it?

How do I stop it coming back?

  • Put every value in a td or th, even a single number.
  • Keep rows in tbody and cells in tr only.
  • Do not use {' '} to space table cells: use CSS.

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 built on the same technologies:

Related fixes

Web apps

next/link throws React.Children.only on its children

Error: React.Children.only expected to receive a single React element child.

React.Children.only accepts exactly one React element and throws for anything else, including an array with one item.

3 causes, each with a fix

Next step

Want this handled for good?

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