简体   繁体   English

文本节点不能作为子节点出现

[英]Text nodes cannot appear as a child of <tbody>

My code is really simple and I checked everything but this is getting this error repeatedly.我的代码非常简单,我检查了所有内容,但这反复出现此错误。 Please suggest to me what can i change.请向我建议我可以改变什么。 I tried using but that dint work.I even checked other answers but they dint work.我尝试使用,但效果很好。我什至检查了其他答案,但效果很好。

 import React from "react";
import { Button, Table } from "react-bootstrap";
import "bootstrap/dist/css/bootstrap.min.css";
import Employees from "./Employees";

const Home = () => {
  return (
    <>
      <div>
        <Table>
          <thead>
            <tr>
              <th>Name</th>
              <th>Age</th>
            </tr>
          </thead>
          <tbody>
            {Employees && Employees > 0 ? Employees.map((item) => {
                  return (
                    <tr key={item.id}>
                      <td>{item.name}</td>
                      <td>{item.age}</td>
                    </tr>
                  );
                })
              : "No data available"}
          </tbody>
        </Table>
      </div>
    </>
  );
};

export default Home;

If there is no data your table would look like如果没有数据,您的表格将如下所示

<table>
  <tbody>
    No data available
  </tbody>
</table>

It needs to have a <tr> and a <td>它需要有一个<tr>和一个<td>

文本节点不能作为子节点出现<div id="text_translate"><p>为什么我会收到此警告?</p><p> Warning: validateDOMNesting(...): Text nodes cannot appear as a child of &lt;table&gt; 。</p><p> 在某些情况下,我看到它是关于一些空白的,但我不明白这在这里是如何应用的。</p><p> 我的代码:</p><pre> return ( &lt;div className="container"&gt; &lt;div&gt; &lt;h2 style={{color: 'red'}}&gt;Lista de Clientes&lt;/h2&gt; &lt;/div&gt; &lt;br/&gt; &lt;table className="table table-bordered"&gt; &lt;thead className="thead-dark"&gt; &lt;tr&gt; &lt;th&gt;#&lt;/th&gt; &lt;th&gt;Nome&lt;/th&gt; &lt;th&gt;Telefone&lt;/th&gt; &lt;th&gt;E-mail&lt;/th&gt; &lt;th&gt;Detalhar&lt;/th&gt; &lt;th&gt;Excluir&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; { inserirClientes } &lt;/table&gt; &lt;/div&gt; );</pre><p> 在这里创建inserirClientes的循环</p><pre> let inserirClientes = this.state.mensagem if (this.state.retorno) { inserirClientes = ( Object.keys(this.state.clientes).map((key, i) =&gt; &lt;tbody key={key + i} &gt; &lt;Clientes remover={this.removerClienteHandler} clienteInfo={this.state.clientes[key]} clickRemove={() =&gt; this.fetchHandler()} indice={i} /&gt; &lt;/tbody&gt; ) ) }</pre><p> 编辑:</p><p> 我开始在循环中生成&lt;tr&gt;而不是&lt;tbody&gt;并且错误仍然存在,但现在我得到了这个:</p><p> Warning: validateDOMNesting(...): Text nodes cannot appear as a child of &lt;tbody&gt;</p><pre> let inserirClientes = this.state.mensagem if (this.state.retorno) { inserirClientes = ( Object.keys(this.state.clientes).map((key, i) =&gt; ( &lt;tr key={`${key}${i}`} &gt; &lt;Clientes remover={this.removerClienteHandler} clienteInfo={this.state.clientes[key]} clickRemove={() =&gt; this.fetchHandler()} indice={i} /&gt; &lt;/tr&gt; )) ) console.log(inserirClientes) } return ( &lt;div className="container"&gt; &lt;div&gt; &lt;h2 style={{color: 'red'}}&gt;Lista de Clientes&lt;/h2&gt; &lt;h4 style={{color: 'red'}}&gt;OBS.: Verificar se é a melhor maneira de se criar tal tabela. Talvez seja possível criar um componente para isso&lt;/h4&gt; &lt;/div&gt; &lt;br/&gt; &lt;table className="table table-bordered"&gt; &lt;thead className="thead-dark"&gt; &lt;tr&gt; &lt;th&gt;#&lt;/th&gt; &lt;th&gt;Nome&lt;/th&gt; &lt;th&gt;Telefone&lt;/th&gt; &lt;th&gt;E-mail&lt;/th&gt; &lt;th&gt;Detalhar&lt;/th&gt; &lt;th&gt;Excluir&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt;{inserirClientes}&lt;/tbody&gt; &lt;/table&gt; &lt;/div&gt; );</pre><p> 知道如何解决这个问题吗?</p></div>[反应JS]<table> </table> - Text nodes cannot appear as a child of <table> [ReactJS]

如何修复警告:validateDOMNesting(...):<div> 不能作为孩子出现</div><div id="text_translate"><p>我将用户列表作为道具传递给 UserItem 组件,以迭代用户列表并将它们显示在表上。 列表显示正确,我的渲染返回中没有任何 div,但我仍然收到错误:index.js:1446 Warning: validateDOMNesting(...): cannot appear as a child of.</p><p> 尝试了网上找到的许多解决方案,但没有一个有效</p><p>用户管理代码:</p><pre> import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { connect } from 'react-redux'; import Spinner from './common/Spinner'; import { getUsers } from '../actions/userActions'; import UserItem from './UserItem'; class UsersManagement extends Component { componentDidMount() { if (.this.props.auth.isAuthenticated) { this.props.history;push('/login'). } this.props;getUsers(), } render() { const { users. loading } = this.props;user; let usersList. if (users === null || loading) { usersList = <Spinner /> } else { if (users.length > 0) { usersList = users.map(user => ( <UserItem key={user._id} user={user} /> )) } else { usersList = <h2>No users</h2> } } return ( <div className="row"> <div className="col-12"> <h1 className="text-center mb-2">Users Management</h1> <button type="button" className="btn btn-success mb-4">New User</button> <table className="table"> <thead> <tr> <th scope="col">Options</th> <th scope="col">Username</th> <th scope="col">Email</th> <th scope="col">Phone Number</th> </tr> </thead> <tbody> {usersList} </tbody> </table> </div> </div> ) } } UsersManagement:propTypes = { getUsers. PropTypes.func,isRequired: auth. PropTypes.object,isRequired: user. PropTypes.object:isRequired } const mapStateToProps = state => ({ auth. state,auth: user. state,user }) export default connect(mapStateToProps; { getUsers })(UsersManagement);</pre><p> 用户项目代码:</p><pre> import React, { Component } from 'react'; import PropTypes from 'prop-types'; class UserItem extends Component { render() { const { user } = this.props; console.log(user); return ( <tr> <th scope="row"> <button type="button" className="btn btn-primary fa-xs mr-1"><i className="fas fa-pencil-alt"></i></button> <button type="button" className="btn btn-danger fa-xs"><i className="far fa-trash-alt"></i></button> </th> <td>{user.username}</td> <td>{user.email}</td> <td>{user.phone}</td> </tr> ) } } UserItem.propTypes = { user: PropTypes.object.isRequired } export default UserItem;</pre><p> 我希望修复警告信息</p></div> - How to fix Warning: validateDOMNesting(...): <div> cannot appear as a child of <tbody>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 validateDOMNesting(...):文本节点不能作为子节点出现 - validateDOMNesting(…): Text nodes cannot appear as a child of <tbody> 文本节点不能作为以下子项出现 <tbody> 。 [阵营] - Text nodes cannot appear as a child of <tbody>. [React] React空白文本节点不能显示为的子级<tbody> - React whitespace text nodes cannot appear as a child of <tbody> 反应:警告:validateDOMNesting(…):文本节点不能显示为以下子项<tbody> - React: Warning: validateDOMNesting(…): Text nodes cannot appear as a child of <tbody> 文本节点不能作为子节点出现<div id="text_translate"><p>为什么我会收到此警告?</p><p> Warning: validateDOMNesting(...): Text nodes cannot appear as a child of &lt;table&gt; 。</p><p> 在某些情况下,我看到它是关于一些空白的,但我不明白这在这里是如何应用的。</p><p> 我的代码:</p><pre> return ( &lt;div className="container"&gt; &lt;div&gt; &lt;h2 style={{color: 'red'}}&gt;Lista de Clientes&lt;/h2&gt; &lt;/div&gt; &lt;br/&gt; &lt;table className="table table-bordered"&gt; &lt;thead className="thead-dark"&gt; &lt;tr&gt; &lt;th&gt;#&lt;/th&gt; &lt;th&gt;Nome&lt;/th&gt; &lt;th&gt;Telefone&lt;/th&gt; &lt;th&gt;E-mail&lt;/th&gt; &lt;th&gt;Detalhar&lt;/th&gt; &lt;th&gt;Excluir&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; { inserirClientes } &lt;/table&gt; &lt;/div&gt; );</pre><p> 在这里创建inserirClientes的循环</p><pre> let inserirClientes = this.state.mensagem if (this.state.retorno) { inserirClientes = ( Object.keys(this.state.clientes).map((key, i) =&gt; &lt;tbody key={key + i} &gt; &lt;Clientes remover={this.removerClienteHandler} clienteInfo={this.state.clientes[key]} clickRemove={() =&gt; this.fetchHandler()} indice={i} /&gt; &lt;/tbody&gt; ) ) }</pre><p> 编辑:</p><p> 我开始在循环中生成&lt;tr&gt;而不是&lt;tbody&gt;并且错误仍然存在,但现在我得到了这个:</p><p> Warning: validateDOMNesting(...): Text nodes cannot appear as a child of &lt;tbody&gt;</p><pre> let inserirClientes = this.state.mensagem if (this.state.retorno) { inserirClientes = ( Object.keys(this.state.clientes).map((key, i) =&gt; ( &lt;tr key={`${key}${i}`} &gt; &lt;Clientes remover={this.removerClienteHandler} clienteInfo={this.state.clientes[key]} clickRemove={() =&gt; this.fetchHandler()} indice={i} /&gt; &lt;/tr&gt; )) ) console.log(inserirClientes) } return ( &lt;div className="container"&gt; &lt;div&gt; &lt;h2 style={{color: 'red'}}&gt;Lista de Clientes&lt;/h2&gt; &lt;h4 style={{color: 'red'}}&gt;OBS.: Verificar se é a melhor maneira de se criar tal tabela. Talvez seja possível criar um componente para isso&lt;/h4&gt; &lt;/div&gt; &lt;br/&gt; &lt;table className="table table-bordered"&gt; &lt;thead className="thead-dark"&gt; &lt;tr&gt; &lt;th&gt;#&lt;/th&gt; &lt;th&gt;Nome&lt;/th&gt; &lt;th&gt;Telefone&lt;/th&gt; &lt;th&gt;E-mail&lt;/th&gt; &lt;th&gt;Detalhar&lt;/th&gt; &lt;th&gt;Excluir&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt;{inserirClientes}&lt;/tbody&gt; &lt;/table&gt; &lt;/div&gt; );</pre><p> 知道如何解决这个问题吗?</p></div>[反应JS]<table> </table> - Text nodes cannot appear as a child of <table> [ReactJS] 警告:validateDOMNesting(…):<div> 不能作为孩子出现<tbody> - Warning: validateDOMNesting(…): <div> cannot appear as a child of <tbody> 反应:警告:validateDOMNesting(...):空白文本节点不能作为子节点出现 - React: Warning: validateDOMNesting(…): Whitespace text nodes cannot appear as a child of <tr> 如何修复警告:validateDOMNesting(...):<div> 不能作为孩子出现</div><div id="text_translate"><p>我将用户列表作为道具传递给 UserItem 组件,以迭代用户列表并将它们显示在表上。 列表显示正确,我的渲染返回中没有任何 div,但我仍然收到错误:index.js:1446 Warning: validateDOMNesting(...): cannot appear as a child of.</p><p> 尝试了网上找到的许多解决方案,但没有一个有效</p><p>用户管理代码:</p><pre> import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { connect } from 'react-redux'; import Spinner from './common/Spinner'; import { getUsers } from '../actions/userActions'; import UserItem from './UserItem'; class UsersManagement extends Component { componentDidMount() { if (.this.props.auth.isAuthenticated) { this.props.history;push('/login'). } this.props;getUsers(), } render() { const { users. loading } = this.props;user; let usersList. if (users === null || loading) { usersList = <Spinner /> } else { if (users.length > 0) { usersList = users.map(user => ( <UserItem key={user._id} user={user} /> )) } else { usersList = <h2>No users</h2> } } return ( <div className="row"> <div className="col-12"> <h1 className="text-center mb-2">Users Management</h1> <button type="button" className="btn btn-success mb-4">New User</button> <table className="table"> <thead> <tr> <th scope="col">Options</th> <th scope="col">Username</th> <th scope="col">Email</th> <th scope="col">Phone Number</th> </tr> </thead> <tbody> {usersList} </tbody> </table> </div> </div> ) } } UsersManagement:propTypes = { getUsers. PropTypes.func,isRequired: auth. PropTypes.object,isRequired: user. PropTypes.object:isRequired } const mapStateToProps = state => ({ auth. state,auth: user. state,user }) export default connect(mapStateToProps; { getUsers })(UsersManagement);</pre><p> 用户项目代码:</p><pre> import React, { Component } from 'react'; import PropTypes from 'prop-types'; class UserItem extends Component { render() { const { user } = this.props; console.log(user); return ( <tr> <th scope="row"> <button type="button" className="btn btn-primary fa-xs mr-1"><i className="fas fa-pencil-alt"></i></button> <button type="button" className="btn btn-danger fa-xs"><i className="far fa-trash-alt"></i></button> </th> <td>{user.username}</td> <td>{user.email}</td> <td>{user.phone}</td> </tr> ) } } UserItem.propTypes = { user: PropTypes.object.isRequired } export default UserItem;</pre><p> 我希望修复警告信息</p></div> - How to fix Warning: validateDOMNesting(...): <div> cannot appear as a child of <tbody> 语义UI React: <thead> 不能作为的子代出现 <tbody> - Semantic UI React : <thead> cannot appear as a child of <tbody> 如何修复 validateDOMNesting(...): 不能作为子级出现。 并且列表中的每个孩子都应该有一个唯一的“关键”道具 - How to fix validateDOMNesting(…): <td> cannot appear as a child of <tbody>. and Each child in a list should have a unique “key” prop
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM