I wrote createIdentifier
for solving React famous bad pattern ‘Using indexes as a key’.
But I’m not sure is it OK.
If you would like, please check my code and give me some comments. Or give me example code that you think the best way.
const createIdentifier = (index: number):string => {
return index.toString() + Math.random().toString();
}
return(
<div>
<ul>
{items.map((item, index) => (
<li key={createIdentifier(index)}>
{item}
</li>
))}
</ul>
</div>
)
Top comments (0)