diff --git a/src/components/Search/index.tsx b/src/components/Search/index.tsx index 0561ce0009cd..da53a4725c59 100644 --- a/src/components/Search/index.tsx +++ b/src/components/Search/index.tsx @@ -1,4 +1,4 @@ -import {useIsFocused, useNavigation} from '@react-navigation/native'; +import {useFocusEffect, useIsFocused, useNavigation} from '@react-navigation/native'; import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react'; import type {NativeScrollEvent, NativeSyntheticEvent, StyleProp, ViewStyle, ViewToken} from 'react-native'; import {View} from 'react-native'; @@ -174,10 +174,12 @@ function Search({queryJSON, currentSearchResults, lastNonEmptySearchResults, onS const {translate} = useLocalize(); const searchListRef = useRef(null); - useEffect(() => { - clearSelectedTransactions(hash); - setCurrentSearchHash(hash); - }, [hash, clearSelectedTransactions, setCurrentSearchHash]); + useFocusEffect( + useCallback(() => { + clearSelectedTransactions(hash); + setCurrentSearchHash(hash); + }, [hash, clearSelectedTransactions, setCurrentSearchHash]), + ); const searchResults = currentSearchResults?.data ? currentSearchResults : lastNonEmptySearchResults; const isSearchResultsEmpty = !searchResults?.data || isSearchResultsEmptyUtil(searchResults);