Hi have a list of items that need to be rendered as a group of buttons, I just want to know which is the good and simplest solution.
first option is just use the key as item key
const sampleoutput =[];
for (const [key, value] of Object.entries(sampleItem)) {
sampleoutput.push(<li>
<a key={key}
href="#!"
onClick={value.onClick}
>
{value.title}
</a>
</li>);
}
the second solution is to use react-uuid
import uuid from "react-uuid";
sampleItem.map((value) => {
return (<li>
<a key={uuid()}
href="#!"
onClick={value.onClick}
>
{value.title}
</a>
</li>);
})
I want also to consider the performance, the second option has another set of processes to generate a key. I am a little concerned with the first option even it is much simpler because of this article https://medium.com/@robinpokorny/index-as-a-key-is-an-anti-pattern-e0349aece318
Thank you in advance for your advice.