Update searchText ref eagerly at setState time
Setting the ref during render doesn't fix the race — if React hasn't re-rendered yet, the ref is just as stale as the closure. Write to the ref at the same time as the setState call so it's current before React schedules the re-render. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -96,9 +96,12 @@ export function SearchScreenShell({
|
||||
const [activeTab, setActiveTab] = useState(() => getTabIndex(tabParam))
|
||||
|
||||
// Query terms
|
||||
const [searchText, setSearchText] = useState<string>(queryParam)
|
||||
const [searchText, _setSearchText] = useState<string>(queryParam)
|
||||
const searchTextRef = useRef(searchText)
|
||||
searchTextRef.current = searchText
|
||||
const setSearchText = (text: string) => {
|
||||
searchTextRef.current = text
|
||||
_setSearchText(text)
|
||||
}
|
||||
const {data: autocompleteData, isFetching: isAutocompleteFetching} =
|
||||
useActorAutocompleteQuery(searchText, true)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user