I dont understand what's wrong with my unique key in a list. I have the above error :
Warning: Each child in a list should have a unique "key" prop. Check the render method of
StockDataTable
This is the part of code involved :
const tBody = (
Object.values(dataItems.dataItems).map(item =>
<>
<tr key={item.id}>
<td>
{item.name}
</td>
<td>
<img src={item.image} alt='' />
</td>
<td>
{item.quantity}
</td>
<td>
{item.price}
</td>
<td>
{item.dueDate}
</td>
<td>
{item.imperative}
</td>
<td>
{item.comment}
</td>
<td>
<Button
variant='link'
onClick={event => handleEpandRow(event, item.id)}
>
{
expandState[item.id]
? 'Hide' : 'Show'
}
</Button>
</td>
</tr>
<>
{
expandedRows.includes(item.id)
? <tr}>
<td colspan='6'>
<div style={{ backgroundColor: '#343A40', color: '#FFF', padding: '10px' }}>
<h2> Details </h2>
<ul>
<li>
<span><b>Name:</b></span> {' '}
<span> {item.name}</span>
</li>
<li>
<span><b>Image:</b></span> {' '}
<span> {item.image}</span>
</li>
<li>
<span><b>Quantity:</b></span> {' '}
<span> {item.quantity} </span>
</li>
<li>
<span><b>Price:</b></span> {' '}
<span> {item.price} </span>
</li>
<li>
<span><b>Due date:</b></span> {' '}
<span> {item.dueDate} </span>
</li>
<li>
<span><b>Imperative:</b></span> {' '}
<span> {item.imperative} </span>
</li>
<li>
<span><b>Comment:</b></span> {' '}
<span> {item.comment} </span>
</li>
</ul>
</div>
</td>
</tr>
: null
}
</>
</>
)
)
return (
<Container>
<Row>
<Col>
<h1> Stock items</h1>
</Col>
</Row>
<Row>
<Col sm={12}>
<Table responsive variant='dark'>
<thead>
<tr>
<th />
<th>Name</th>
<th>Image</th>
<th>Quantity</th>
<th>Price</th>
<th>Due date</th>
<th>Imperative</th>
<th>Comment</th>
</tr>
</thead>
<tbody>
{tBody}
</tbody>
</Table>
</Col>
</Row>
</Container>
)
I tried to use index (even if it's depricated) but I still have the error message. I don't know if I am setting the key at the right place. item.id is must be used several times but I don't know why.
