Data on grid was duplicated when grid re-render during device rotation.
sanghavan opened this issue · 8 comments
I already faced to issue which data on grid was duplicated when grid re-render during device rotation.
react-native-super-grid version: 4.0.3
react-native version: 0.61.5
Portrait mode:
Landscape mode:
data:
[
{ "title": "name", "value": "a" },
{ "title": "name", "value": "a" },
{ "title": "name", "value": "a" }
]
The data is loading on my own custom cell.
I found the reason, it's by callback into keyExtractor
returned key as duplication because index = 0 for all. Don't sure why.
keyExtractor={(_item, index) => index.toString()}
I see.
index
in keyExtractor is position of the item that particular row (not the index among all the items). Since each of your row has only one item, the index passed is always 0.
I will try to fix it.
By the way, it is always good to rely on some property of the item as the key
.
I believe in your case not passing the keyExtractor function should also fix the problem.
Thank @saleel for replying.
In my case, I tried on return unique value in keyExtractor
. It's working right now. But the index
should be unique.
@saleel How about add section
as like index
to keyExtractor args?
const keyExtractor = (item: Diary, section: number, index: number) => {
return `${section}-${index}`
}
It can be the unique key.
@JeffGuKang I don't think it will work. The problem here is index points to the index of the row and not to an individual item. We need to calculate the actual item index from inside and pass it here.
But ideally, key should be based on a unique parameter of the item and not based on the index.
I have fixed the index in keyExtractor to return the correct itemIndex in the new version (4.4.2). Closing this issue.