Fix stale searchText in search submit handler (#10251)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -96,7 +96,12 @@ export function SearchScreenShell({
|
|||||||
const [activeTab, setActiveTab] = useState(() => getTabIndex(tabParam))
|
const [activeTab, setActiveTab] = useState(() => getTabIndex(tabParam))
|
||||||
|
|
||||||
// Query terms
|
// Query terms
|
||||||
const [searchText, setSearchText] = useState<string>(queryParam)
|
const [searchText, _setSearchText] = useState<string>(queryParam)
|
||||||
|
const searchTextRef = useRef(searchText)
|
||||||
|
const setSearchText = (text: string) => {
|
||||||
|
searchTextRef.current = text
|
||||||
|
_setSearchText(text)
|
||||||
|
}
|
||||||
const {data: autocompleteData, isFetching: isAutocompleteFetching} =
|
const {data: autocompleteData, isFetching: isAutocompleteFetching} =
|
||||||
useActorAutocompleteQuery(searchText, true)
|
useActorAutocompleteQuery(searchText, true)
|
||||||
|
|
||||||
@@ -227,15 +232,12 @@ export function SearchScreenShell({
|
|||||||
}
|
}
|
||||||
}, [setShowAutocomplete, setSearchText, navigation, route.params, route.name])
|
}, [setShowAutocomplete, setSearchText, navigation, route.params, route.name])
|
||||||
|
|
||||||
const onSubmit = useCallback(
|
const onSubmit = (source: 'typed' | 'autocomplete') => () => {
|
||||||
(source: 'typed' | 'autocomplete') => () => {
|
|
||||||
ax.metric('search:query', {
|
ax.metric('search:query', {
|
||||||
source,
|
source,
|
||||||
})
|
})
|
||||||
navigateToItem(searchText)
|
navigateToItem(searchTextRef.current)
|
||||||
},
|
}
|
||||||
[ax, navigateToItem, searchText],
|
|
||||||
)
|
|
||||||
|
|
||||||
const onAutocompleteResultPress = useCallback(() => {
|
const onAutocompleteResultPress = useCallback(() => {
|
||||||
if (IS_WEB) {
|
if (IS_WEB) {
|
||||||
|
|||||||
Reference in New Issue
Block a user