Skip to content

Commit

Permalink
refactor: move debounce to handleSearch initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
ThorsAngerVaNeT committed Aug 13, 2023
1 parent c172867 commit da7ccda
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions client/src/components/UserSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ export function UserSearch(props: UserProps) {
setData(defaultValues ?? []);
}, [props.defaultValues]);

const handleSearch = async (value: string) => {
const handleSearch = debounce(async (value: string) => {
value = value.trim();
if (value) {
const data = await searchFn(value, onlyStudentsWithoutMentorShown);
setData(data);
} else {
setData(props.defaultValues ?? []);
}
};
}, 300);

return (
<Select
Expand All @@ -49,7 +49,7 @@ export function UserSearch(props: UserProps) {
defaultActiveFirstOption={false}
showArrow={defaultValues ? Boolean(defaultValues.length) : false}
filterOption={false}
onSearch={debounce(handleSearch, 300)}
onSearch={handleSearch}
placeholder={defaultValues?.length ?? 0 > 0 ? 'Select...' : 'Search...'}
notFoundContent={null}
>
Expand Down

0 comments on commit da7ccda

Please sign in to comment.