Why am I receiving this warning?
Warning: validateDOMNesting(...): Text nodes cannot appear as a child of <table>.
In some cases I saw that it is about some white spaces, but I don't see how this applies in here.
My code:
return (
<div className="container">
<div>
<h2 style={{color: 'red'}}>Lista de Clientes</h2>
</div>
<br/>
<table className="table table-bordered">
<thead className="thead-dark">
<tr>
<th>#</th>
<th>Nome</th>
<th>Telefone</th>
<th>E-mail</th>
<th>Detalhar</th>
<th>Excluir</th>
</tr>
</thead>
{ inserirClientes }
</table>
</div>
);
In here the loop that creates inserirClientes
let inserirClientes = this.state.mensagem
if (this.state.retorno) {
inserirClientes = (
Object.keys(this.state.clientes)
.map((key, i) =>
<tbody key={key + i} >
<Clientes
remover={this.removerClienteHandler}
clienteInfo={this.state.clientes[key]}
clickRemove={() => this.fetchHandler()}
indice={i}
/>
</tbody>
)
)
}
EDIT:
I started generating <tr> in the loop instead of <tbody> and the error persists, but now I am getting this:
Warning: validateDOMNesting(...): Text nodes cannot appear as a child of <tbody>
let inserirClientes = this.state.mensagem
if (this.state.retorno) {
inserirClientes = (
Object.keys(this.state.clientes)
.map((key, i) => (
<tr key={`${key}${i}`} >
<Clientes
remover={this.removerClienteHandler}
clienteInfo={this.state.clientes[key]}
clickRemove={() => this.fetchHandler()}
indice={i}
/>
</tr>
))
)
console.log(inserirClientes)
}
return (
<div className="container">
<div>
<h2 style={{color: 'red'}}>Lista de Clientes</h2>
<h4 style={{color: 'red'}}>OBS.: Verificar se é a melhor maneira de se criar tal tabela. Talvez seja possível criar um componente para isso</h4>
</div>
<br/>
<table className="table table-bordered">
<thead className="thead-dark">
<tr>
<th>#</th>
<th>Nome</th>
<th>Telefone</th>
<th>E-mail</th>
<th>Detalhar</th>
<th>Excluir</th>
</tr>
</thead>
<tbody>{inserirClientes}</tbody>
</table>
</div>
);
Any idea how to solve this?