Closed itajenglish closed 2 years ago
This solution worked for me. https://stackoverflow.com/a/47940952/1065877
I am not sure why I can't reproduce this on my side. I'll see how I can handle this internally when I can reproduce this.
Do you mind sharing your code from the YouTube video? Maybe you did something differently?
Sure~!
const LayoutTwo: FC<Props> = ({
ITEM_CNT,
items,
isLoadingNext,
loadNext,
refetch,
}) => {
const {viewedItemIds} = useDiscoveryContext();
const filteredItems = useMemo(() => {
return items.filter((item) => !viewedItemIds.has(item.id));
}, [items, viewedItemIds]);
return (
<MasonryList
data={filteredItems}
keyExtractor={(item, index): string => index.toString()}
numColumns={2}
showsVerticalScrollIndicator={false}
LoadingView={
<View
style={{
height: 40,
width: '100%',
}}>
<LoadingIndicator />
</View>
}
renderItem={({item}): ReactElement => {
return <DiscoveryCard isItem itemData={item} isDiscovery={false} />;
}}
refreshing={isLoadingNext}
onRefresh={() => {
refetch?.({first: ITEM_CNT}, {fetchPolicy: 'network-only'});
}}
onEndReachedThreshold={0.1}
onEndReached={() => loadNext?.(ITEM_CNT)}
/>
);
};
onEndReached is called multiple times in facebook's flatlist component as well I doubt you have done something wrong in your library.
I suspect this issue is due to re-rendering
. I've made masonry list
as a pure component from 1.1.0
.
Please try this again and come back if it still is a problem @itajenglish
Hi, @hyochan Still experiencing the same issues in the latest version.
I also had a problem with onEndReached calling multiple times in the latest version.
Describe the bug
onEndReached
method gets fired multiple times when scrolling to the end of scroll view when trying to fetch next set of data for pagination.Code:
To Reproduce Steps to reproduce the behavior:
Expected behavior Should only fire one time when reaching end of list
Screenshots If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
Smartphone (please complete the following information):
Additional context Add any other context about the problem here.