Skip to content

Commit 29294a3

Browse files
authored
Merge pull request Expensify#65427 from bernhardoj/fix/63300-current-hash-not-updated-when-changing-screen-with-back-button
Update current search hash when screen is focused
2 parents 359c8c2 + 9f067bd commit 29294a3

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

src/components/Search/index.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {useIsFocused, useNavigation} from '@react-navigation/native';
1+
import {useFocusEffect, useIsFocused, useNavigation} from '@react-navigation/native';
22
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
33
import type {NativeScrollEvent, NativeSyntheticEvent, StyleProp, ViewStyle, ViewToken} from 'react-native';
44
import {View} from 'react-native';
@@ -174,10 +174,12 @@ function Search({queryJSON, currentSearchResults, lastNonEmptySearchResults, onS
174174
const {translate} = useLocalize();
175175
const searchListRef = useRef<SelectionListHandle | null>(null);
176176

177-
useEffect(() => {
178-
clearSelectedTransactions(hash);
179-
setCurrentSearchHash(hash);
180-
}, [hash, clearSelectedTransactions, setCurrentSearchHash]);
177+
useFocusEffect(
178+
useCallback(() => {
179+
clearSelectedTransactions(hash);
180+
setCurrentSearchHash(hash);
181+
}, [hash, clearSelectedTransactions, setCurrentSearchHash]),
182+
);
181183

182184
const searchResults = currentSearchResults?.data ? currentSearchResults : lastNonEmptySearchResults;
183185
const isSearchResultsEmpty = !searchResults?.data || isSearchResultsEmptyUtil(searchResults);

0 commit comments

Comments
 (0)