Whitespace text nodes cannot appear as a child of <table>
See original GitHub issueWhen I want to create a React table from a multi line string I will get a warning from React:
index.js:1452 Warning: validateDOMNesting(...): Whitespace text nodes cannot appear as a child of <table>. Make sure you don't have any extra whitespace between tags on each line of your source code.
Example code that will trigger the error
render() {
const table = parser.parse(`
<table>
<tbody>
<tr>
<td>Lorem Ipsum</td>
</tr>
</tbody>
</table>
`);
return (
<React.Fragment>
{table}
</React.Fragment>
);
Off course I can fix this warning by writing the table on one line, but that is not the solution where I’m looking for.
const table = parser.parse('<table><tbody><tr><td>Lorem Ipsum</td></tr></tbody></table>');
With dangerouslySetInnerHTML I can use a multi line string without any problems. I also tried the package html-react-parser but it will have the same problem.
Thanks for your time and help, Ben
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (4 by maintainers)
Top Results From Across the Web
validateDOMNesting: #text cannot appear as a child of <tr ...
So, any text to be displayed inside a table row must be placed inside <td> ... Whitespace text nodes cannot appear as a...
Read more >Whitespace text nodes cannot appear as a child of <tbody ...
Error 2. Whitespace text nodes cannot appear as a child of <tbody>. Make sure you don't have any extra whitespace between tags on...
Read more >validateDOMNesting: #text cannot appear as a child of <tr ...
Whitespace text nodes cannot appear as a child of <tbody> . Make sure you don't have any extra white space between tags on...
Read more >React DOM elements should be nested properly - DeepScan
React Warning: validateDOMNesting(…): Whitespace text nodes cannot appear as a child of <tr>. Make sure you don't have any extra whitespace ...
Read more >validatedomnesting(...): <div> cannot appear as a child of ...
Warning: validateDOMNesting(...): Whitespace text nodes cannot appear as a child of <tr>. Make sure you don't have any extra whitespace between tags on...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
In case it isn’t clear how to drop whitespace nodes, here’s a TypeScript example:
On my end. I removed all spaces in between my fragment.