Просмотр исходного кода

determine if a string that has been debounced is empty

Shun Miyazawa 2 лет назад
Родитель
Сommit
5d05f2ad66

+ 3 - 3
apps/app/src/features/search/client/components/SearchResultMenuItem.tsx

@@ -12,11 +12,11 @@ type Props = {
 export const SearchResultMenuItem = (props: Props): JSX.Element => {
   const { searchKeyword } = props;
 
-  const isEmptyKeyword = searchKeyword.trim() === '';
-
   const debouncedKeyword = useDebounce(searchKeyword, 500);
 
-  const { data: searchResult } = useSWRxSearch(isEmptyKeyword ? null : debouncedKeyword, null, { limit: 10 });
+  const isEmptyKeyword = debouncedKeyword.trim() === '';
+
+  const { data: searchResult } = useSWRxSearch(isEmptyKeyword ? null : searchKeyword, null, { limit: 10 });
 
   if (isEmptyKeyword || searchResult == null || searchResult.data.length === 0) {
     return <></>;