react:Text nodes cannot appear as a child

Warning: validateDOMNesting(...): Text nodes cannot appear as a child of <thead>.
index.js:1 Warning: validateDOMNesting(...): Text nodes cannot appear as a child of <tbody>.

這種情況一般是表單節點是不存在的情況,我們沒修改的時候是這樣的

<table className="table text-center">
  <thead>{this.props.tableHead.length }</thead>
  <tbody>{this.props.tableData.length }</tbody>
</table>

修改完是這樣的

<thead>{this.props.tableHead.length > 0 ? this.props.tableHead: <tr></tr>}</thead>
<tbody>{this.props.tableData.length > 0 ? this.props.tableData: <tr></tr>}</tbody>

找了一下午,最終還是學長來給我看出來了

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章