REACT ERROR cannot appear as a child of . See (unknown) > thead > th

后端 未结 4 995
青春惊慌失措
青春惊慌失措 2021-02-11 11:56

I am working on a react - rails app and I keep getting this error in my console:

```
Warning: validateDOMNesting(...):  cannot appear as a child of &l         


        
相关标签:
4条回答
  • 2021-02-11 12:16

    The only direct children allowed for thead are tr elements, not th.

    <table>
      <thead>
        <tr>
          <th />
        </tr>
      </thead>
      ...
    </table>
    
    0 讨论(0)
  • 2021-02-11 12:28

    Well th should be nested under a tr not a thead. Docs

    <table>
      <thead>
        <tr>
          <th>name</th>
          <th>age</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>john</td>
          <td>33</td>
        </tr>
        <tr>
          <td>smith</td>
          <td>22</td>
        </tr>
        <tr>
          <td>jane</td>
          <td>24</td>
        </tr>
      </tbody>
    </table>

    0 讨论(0)
  • 2021-02-11 12:28

    I've had this error come up because of mistakes elsewhere in my list.

    For example @Sag1v has <tbody> instead of </tbody> to close the body of his list and I bet that is causing the error.

    0 讨论(0)
  • 2021-02-11 12:40

    Mistakenly, I had tbody inside thead

    (1)

    <thead>
    ...
      <tbody>
      ...
      </tbody>
    </thead>
    

    instead of (2)

    <thead>
    ...
    </thead>
    
    <tbody>
    ...
    </tbody>
    

    Changing to (2) solved my problem.

    0 讨论(0)
提交回复
热议问题