React Native - Use a keyExtractor with FlatList

前端 未结 8 1182
暖寄归人
暖寄归人 2021-02-01 14:05

I have been getting the:

\"VirtualizedList: missing keys for items, make sure to specify a key property on an item or provide a custom keyExtractor\"

8条回答
  •  暖寄归人
    2021-02-01 14:51

    Best unique key extractor for react native

    function looks like:

      keyExtractor = item => {
        return item.id.toString() + new Date().getTime().toString() + (Math.floor(Math.random() * Math.floor(new Date().getTime()))).toString();  };
    

    or without item fields:

      keyExtractor = () => {
        return new Date().getTime().toString() + (Math.floor(Math.random() * Math.floor(new Date().getTime()))).toString();  };
    

提交回复
热议问题