In my React component, I want to use the map function to display some messages that come in an array. The array is very simple, just the messages:
const messages = [
"John called and left a message.",
"Marketing report is ready!",
"Today's sales meeting is cancelled."
]
I don't want to complicate this array anymore than necessary so there's no id for these messages.
When I try to use the map function in my React component, it wants me to have a unique key/id for each item. How do I use the index for each item in this array?
I tried this code
<ul>
{messages.map(item => {
<li key={item.index}>{item}</li>
})}
</ul>
but getting an error message that reads:
Each child in an array or iterator should have a unique "key" prop.