From c172867f25046461f0f10a698aad37cf4a4516fc Mon Sep 17 00:00:00 2001 From: Vadzim Antonau Date: Sun, 13 Aug 2023 11:02:48 +0300 Subject: [PATCH] Revert "feat: replace lodash debounce for useDebounce hook in UserSearch" This reverts commit 3a136a38b1260b572ab8850aa3cff1ec60a48868. --- client/src/components/UserSearch.tsx | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/client/src/components/UserSearch.tsx b/client/src/components/UserSearch.tsx index 78e5d34924..94ca3d8da1 100644 --- a/client/src/components/UserSearch.tsx +++ b/client/src/components/UserSearch.tsx @@ -1,10 +1,9 @@ import { useState, useEffect } from 'react'; import { Select, Typography } from 'antd'; import { GithubAvatar } from 'components/GithubAvatar'; -import get from 'lodash/get'; +import { get, debounce } from 'lodash'; import { SelectProps } from 'antd/lib/select'; import type { SearchStudent } from 'services/course'; -import { useDebounce } from 'react-use'; type Person = { id: number; githubId: string; name: string } | SearchStudent; @@ -18,8 +17,6 @@ export type UserProps = SelectProps & { export function UserSearch(props: UserProps) { const [data, setData] = useState([]); - const [value, setValue] = useState(''); - const [debouncedValue, setDebouncedValue] = useState(''); const { searchFn = defaultSearch, defaultValues, @@ -33,23 +30,15 @@ export function UserSearch(props: UserProps) { setData(defaultValues ?? []); }, [props.defaultValues]); - useEffect(() => { - if (debouncedValue) { - searchFn(debouncedValue, onlyStudentsWithoutMentorShown).then(data => setData(data)); + const handleSearch = async (value: string) => { + value = value.trim(); + if (value) { + const data = await searchFn(value, onlyStudentsWithoutMentorShown); + setData(data); } else { setData(props.defaultValues ?? []); } - }, [debouncedValue]); - - useDebounce( - () => { - setDebouncedValue(value); - }, - 300, - [value], - ); - - const handleSearch = (value: string) => setValue(value.trim()); + }; return (