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>

找了一下午,最终还是学长来给我看出来了

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