I'm trying to implement a an array of options for a form. Even though I have already implemented the key prop, I keep getting this error:
Each child in an array should have a unique "key" prop.
The options are taken from the following array of options:
[
{
"id": 1,
"label": "Active",
"value": "Active"
},
{
"id": 2,
"label": "Inactive",
"value": "Inactive"
},
{
"id": 3,
"label": "Alert",
"value": "Alert"
}
]
Below follows my code:
<li>
<label className={styles.destaque}>Status</label>
<select
value={camposFormulario?.status}
onChange={(event) =>
setCamposFormulario((prev) => ({
...prev,
['status']: event.target.value,
}))
}
>
{statusList.map((option: any) => {
return (
<option key={option.id} value={option.value}>
{option.label}
</option>
);
})}
</select>
</li>
I have read this topic: Understanding unique keys for array children in React.js and I believe I have followed the indications.
Any help would be much appreciated.
Thanks a lot!
Edit:
Also, if I change the map
function by this it works:
<option>Ativo</option>
<option>Inativo</option>
<option>Em Alerta</option>