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>

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

posted @ 2020-09-28 22:49  SteveYu  阅读(706)  评论(0编辑  收藏  举报