Skip to content

Commit 652d2ff

Browse files
authored
Merge pull request #51480 from software-mansion-labs/fix/search-infinite-loading
2 parents 9508b17 + be52e2b commit 652d2ff

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/components/Search/index.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {useIsFocused, useNavigation} from '@react-navigation/native';
22
import type {StackNavigationProp} from '@react-navigation/stack';
3-
import React, {useCallback, useEffect, useRef, useState} from 'react';
3+
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
44
import {View} from 'react-native';
55
import type {NativeScrollEvent, NativeSyntheticEvent, StyleProp, ViewStyle} from 'react-native';
66
import type {OnyxEntry} from 'react-native-onyx';
@@ -196,7 +196,13 @@ function Search({queryJSON, onSearchListScroll, contentContainerStyle}: SearchPr
196196
const shouldShowLoadingMoreItems = !shouldShowLoadingState && searchResults?.search?.isLoading && searchResults?.search?.offset > 0;
197197
const isSearchResultsEmpty = !searchResults?.data || SearchUIUtils.isSearchResultsEmpty(searchResults);
198198
const prevIsSearchResultEmpty = usePrevious(isSearchResultsEmpty);
199-
const data = searchResults === undefined ? [] : SearchUIUtils.getSections(type, status, searchResults.data, searchResults.search);
199+
200+
const data = useMemo(() => {
201+
if (searchResults === undefined) {
202+
return [];
203+
}
204+
return SearchUIUtils.getSections(type, status, searchResults.data, searchResults.search);
205+
}, [searchResults, status, type]);
200206

201207
useEffect(() => {
202208
/** We only want to display the skeleton for the status filters the first time we load them for a specific data type */

0 commit comments

Comments
 (0)