Drop autofocus and move the search reset out of render. [skip build]
Checks / checks (push) Successful in 2m6s
Trigger cinny-mobile / dispatch (push) Successful in 1s

This commit is contained in:
2026-11-01 10:48:55 +11:00
parent 2db4fe4734
commit 6805762834
2 changed files with 7 additions and 8 deletions
@@ -275,7 +275,6 @@ export function ForumNewPostModal({
onChange={(e) => setTitle(e.target.value)}
maxLength={140}
required
autoFocus
placeholder="Title"
aria-label="Title"
autoComplete="off"
+7 -7
View File
@@ -112,8 +112,6 @@ export const useAsyncSearch = <TSearchItem extends object | string | number>(
const [result, setResult] = useState<UseAsyncSearchResult<TSearchItem>>();
const [searchCallback, terminateSearch] = useMemo(() => {
setResult(undefined);
const handleMatch: MatchHandler<TSearchItem> = (item, query) => {
const itemStr = getItemStr(item, query);
@@ -143,13 +141,15 @@ export const useAsyncSearch = <TSearchItem extends object | string | number>(
setResult(undefined);
}, [terminateSearch]);
useEffect(
() => () => {
useEffect(() => {
// clear stale results whenever the search source is recreated
setResult(undefined);
return () => {
// terminate any ongoing search request on unmount.
terminateSearch();
},
[terminateSearch],
);
};
}, [terminateSearch]);
return [result, searchHandler, resetHandler];
};