Drop autofocus and move the search reset out of render. [skip build]
This commit is contained in:
@@ -275,7 +275,6 @@ export function ForumNewPostModal({
|
||||
onChange={(e) => setTitle(e.target.value)}
|
||||
maxLength={140}
|
||||
required
|
||||
autoFocus
|
||||
placeholder="Title"
|
||||
aria-label="Title"
|
||||
autoComplete="off"
|
||||
|
||||
@@ -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];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user