DEV Community


Posted on

【Please check my code】React bad pattern

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();

      {, index) => (
        <li key={createIdentifier(index)}>

Enter fullscreen mode Exit fullscreen mode

Top comments (0)