|
1 | 1 | import {useIsFocused, useNavigation} from '@react-navigation/native';
|
2 | 2 | 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'; |
4 | 4 | import {View} from 'react-native';
|
5 | 5 | import type {NativeScrollEvent, NativeSyntheticEvent, StyleProp, ViewStyle} from 'react-native';
|
6 | 6 | import type {OnyxEntry} from 'react-native-onyx';
|
@@ -196,7 +196,13 @@ function Search({queryJSON, onSearchListScroll, contentContainerStyle}: SearchPr
|
196 | 196 | const shouldShowLoadingMoreItems = !shouldShowLoadingState && searchResults?.search?.isLoading && searchResults?.search?.offset > 0;
|
197 | 197 | const isSearchResultsEmpty = !searchResults?.data || SearchUIUtils.isSearchResultsEmpty(searchResults);
|
198 | 198 | 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]); |
200 | 206 |
|
201 | 207 | useEffect(() => {
|
202 | 208 | /** 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