I am getting below error:
Warning: Each child in a list should have a unique "key" prop.
Check the render method of `App`.
See https://reactjs.org/link/warning-keys for more information.
WithStyles@http://localhost:3000/static/js/vendors~main.chunk.js:39295:25
App@http://localhost:3000/static/js/main.chunk.js:197:91
Here is my code:
function Table({ countries }) {
return (
<div className="table">
{countries.map(({ country, cases }) => {
<tr>
<td>{country}</td>
<td>
<strong>{cases}</strong>
</td>
</tr>
})}
</div>
)
}
First of all you are not returning element iterating the countries. React throws a warning if you do not provide key for each element you render within the loop as key is needed for react to identify which element has been changed. You can pass index to the key as the country or the cases can be same.
Table({ countries }) {
return (
<div className="table">
{
countries.map(({country, cases}, index) => {
return (
<tr key={index}>
<td>{country}</td>
<td>
<strong>{cases}</strong>
</td>
</tr>
)
)
}
</div>
);
}