I\'m trying to get this work:
Orders:
render () {
const orders = this.state.orders.map((o
Or more elegant:
render () {
return (
<table>
<tbody>
{this.state.orders.map((order, index) => (
return (<OrderRow order={order} key={index} />);
)}
</tbody>
</table>
);
}
Something like this:
render () {
return (
<table>
<tbody>
{this.state.orders.map((order, index) => {
<tr index={index}>
<td>{order.number}</td>
<td>{order.products}</td>
<td>{order.shippingDate}</td>
<td>{order.status}</td>
</tr>
}}
</tbody>
</table>
);
}
It renders tr into div use .map() instead :)
Wrap your OrderRow <tr>
in <tbody>
as explained in issue here, Browsers need the <tbody>
tag. If it is not in your code, then the browser will automatically insert it. This will work fine on first render, but when the table gets updated, then the DOM tree is different from what React expects. This can give strange bugs, therefore React warns you to insert the <tbody>
.
OrderRow
render () {
return (
<table>
<tbody>
<tr>
<td>{this.props.order.number}</td>
<td>{this.props.order.products}</td>
<td>{this.props.order.shippingDate}</td>
<td>{this.props.order.status}</td>
</tr>
</tbody>
</table>
);
}