React warns that text cannot appear as a child of a table row
In 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.
Fix it fast
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"2Match what you see, then jump to its fix
- 1
A literal word, or {' '}, sits between two td elementsText or a space is written between the cellsFix - 2
{count}, {label} or {cond && 'text'} is a direct child of trAn expression in the row returns a string or numberFix - 3
rows.map(...) inside tr, or a map callback with { } and no returnMapped rows return text or several elements without a keyFix
- 1
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 devConfirmed by raw.githubusercontent.com
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 devConfirmed by html.spec.whatwg.org
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 devConfirmed by react.dev
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- TaskvareA task and project-management suite: React on the web, Flutter on mobile, TypeScript underneath.
Related fixes
Web apps
React warns that an <a> is nested inside another <a>
Warning: validateDOMNesting(...): <a> cannot appear as a descendant of <a>.
HTML does not allow a link inside a link.
2 causes, each with a fixWeb apps
ESLint says an element in a list is missing its key prop
react/jsx-key
react/jsx-key fires when an element returned from map, Array.from or an array literal has no key.
3 causes, each with a fixWeb apps
There is no tailwind.config.js after installing Tailwind 4 and HeroUI in Next.js
HeroUI components render unstyled
Nothing is broken: Tailwind CSS 4 is configured in CSS and no longer creates tailwind.config.js.
3 causes, each with a fixWeb apps
react-i18next shows the wrong plural form for a count, or prints the key instead of the text
t('item') prints the key item instead of a translated sentence
i18next picks a plural from the count option and looks for keys ending in _one, _other and so on.
4 causes, each with a fixWeb apps
useSession throws because there is no SessionProvider above it
[next-auth]: `useSession` must be wrapped in a <SessionProvider />
useSession reads the session from React Context, and SessionProvider is what creates that context.
3 causes, each with a fixWeb 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