diff --git a/src/components/Search/index.tsx b/src/components/Search/index.tsx index c20b8f0eebe0..038702f7195f 100644 --- a/src/components/Search/index.tsx +++ b/src/components/Search/index.tsx @@ -177,9 +177,12 @@ function Search({queryJSON, currentSearchResults, lastNonEmptySearchResults, onS const shouldGroupByReports = groupBy === CONST.SEARCH.GROUP_BY.REPORTS; useEffect(() => { + if (!isFocused) { + return; + } clearSelectedTransactions(hash); setCurrentSearchHash(hash); - }, [hash, clearSelectedTransactions, setCurrentSearchHash]); + }, [hash, clearSelectedTransactions, setCurrentSearchHash, isFocused]); const searchResults = currentSearchResults?.data ? currentSearchResults : lastNonEmptySearchResults; const isSearchResultsEmpty = !searchResults?.data || isSearchResultsEmptyUtil(searchResults); @@ -217,12 +220,11 @@ function Search({queryJSON, currentSearchResults, lastNonEmptySearchResults, onS }, [isSmallScreenWidth, selectedTransactions, selectionMode?.isEnabled]); useEffect(() => { - if (isOffline) { + if (isOffline || !isFocused) { return; } - handleSearch({queryJSON, offset}); - }, [handleSearch, isOffline, offset, queryJSON]); + }, [handleSearch, isOffline, offset, queryJSON, isFocused]); const {newSearchResultKey, handleSelectionListScroll} = useSearchHighlightAndScroll({ searchResults,