20

So why is react complaining that I cannot have a 'tr' as a child of a 'td'?

              <tr>
                <td colSpan={2}>
                  <tr>
                    <td>
                      <Some picture>
                    </td>
                    <td>
                      <some content>
                    </td>
                  </tr>
                  <tr>
                    <td colSpan={2}>
                      <p>Paragraph stuff</p>
                    </td>
                  </tr>
                </td>
              </tr>

Maybe I have to put another table or something?

janhartmann
  • 14,713
  • 15
  • 82
  • 138
pizzae
  • 2,815
  • 6
  • 26
  • 45

1 Answers1

33

Yes, you'll need this mark up:

<table>
    <tbody>
        <tr>
            <td colspan={2}>
                <table>
                    <tbody>
                        <tr>
                            <td></td>
                            <td></td>
                        </tr>
                        <tr>
                            <td colspan={2}>
                                <p>Paragraph stuff</p>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </td>
        </tr>
    </tbody>
</table>

It is not valid markup to have a nested <tr> within a <td>. Use another table to layout it.

According to https://github.com/facebook/react/issues/5652 you will need to wrap your table contents in a tbody:

Browsers need the <tbody> tag. If it is not in your code, then the browser will automatically insert it. This will work fine on first render, but when the table gets updated, then the DOM tree is different from what React expects. This can give strange bugs, therefore React warns you to insert the <tbody>. It is a really helpful warning.

Thanks @Stefan Dragnev

John Weisz
  • 30,137
  • 13
  • 89
  • 132
janhartmann
  • 14,713
  • 15
  • 82
  • 138