error: Do not use Array index in keys

后端 未结 4 464
离开以前
离开以前 2020-11-27 21:57

I am using index to generate key in a list. However, es-lint generates an error for the same. React doc also states that using the item index as a key should be used as last

4条回答
  •  一生所求
    2020-11-27 22:55

    use the following lib "react-uuid" : https://www.npmjs.com/package/react-uuid.

    react-uuid basically create random ids when you call it each time.

    import React from 'react'
    import uuid from 'react-uuid'
    
    const array = ['one', 'two', 'three']
    
    export const LineItem = item => 
  • {item}
  • export const List = () => array.map(item => )

    and this should solve the issue.

提交回复
热议问题