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:
Eric Bailey
2026-04-14 11:28:32 -05:00
parent 4eb9b36e3d
commit 614df8409f
+5 -2
View File
@@ -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)