Drop autofocus and move the search reset out of render. [skip build]
This commit is contained in:
1 parent
2db4fe4734
commit
6805762834
2 files changed
+7
-8
No files matched your search
@@ -275,7 +275,6 @@ export function ForumNewPostModal({
|
|||||||
onChange={(e) => setTitle(e.target.value)}
|
onChange={(e) => setTitle(e.target.value)}
|
||||||
maxLength={140}
|
maxLength={140}
|
||||||
required
|
required
|
||||||
autoFocus
|
|
||||||
placeholder="Title"
|
placeholder="Title"
|
||||||
aria-label="Title"
|
aria-label="Title"
|
||||||
autoComplete="off"
|
autoComplete="off"
|
||||||
|
|||||||
@@ -112,8 +112,6 @@ export const useAsyncSearch = <TSearchItem extends object | string | number>(
|
|||||||
const [result, setResult] = useState<UseAsyncSearchResult<TSearchItem>>();
|
const [result, setResult] = useState<UseAsyncSearchResult<TSearchItem>>();
|
||||||
|
|
||||||
const [searchCallback, terminateSearch] = useMemo(() => {
|
const [searchCallback, terminateSearch] = useMemo(() => {
|
||||||
setResult(undefined);
|
|
||||||
|
|
||||||
const handleMatch: MatchHandler<TSearchItem> = (item, query) => {
|
const handleMatch: MatchHandler<TSearchItem> = (item, query) => {
|
||||||
const itemStr = getItemStr(item, query);
|
const itemStr = getItemStr(item, query);
|
||||||
|
|
||||||
@@ -143,13 +141,15 @@ export const useAsyncSearch = <TSearchItem extends object | string | number>(
|
|||||||
setResult(undefined);
|
setResult(undefined);
|
||||||
}, [terminateSearch]);
|
}, [terminateSearch]);
|
||||||
|
|
||||||
useEffect(
|
useEffect(() => {
|
||||||
() => () => {
|
// clear stale results whenever the search source is recreated
|
||||||
|
setResult(undefined);
|
||||||
|
|
||||||
|
return () => {
|
||||||
// terminate any ongoing search request on unmount.
|
// terminate any ongoing search request on unmount.
|
||||||
terminateSearch();
|
terminateSearch();
|
||||||
},
|
};
|
||||||
[terminateSearch],
|
}, [terminateSearch]);
|
||||||
);
|
|
||||||
|
|
||||||
return [result, searchHandler, resetHandler];
|
return [result, searchHandler, resetHandler];
|
||||||
};
|
};
|
||||||
Reference in new issue
Block a user