Skip to content

Commit

Permalink
検索を軽くした
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-20 committed Mar 24, 2024
1 parent 859bac6 commit eaf4061
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion workspaces/app/src/pages/SearchPage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Suspense, useCallback, useEffect, useId, useState } from 'react';
import { useDebounce } from 'react-use';

import { useBookList } from '../../features/book/hooks/useBookList';
import { Box } from '../../foundation/components/Box';
Expand All @@ -16,6 +17,9 @@ const SearchPage: React.FC = () => {
const [isClient, setIsClient] = useState(false);
const [keyword, setKeyword] = useState('');

const [debouncedKeyword, setDebouncedKeyword] = useState(keyword);
useDebounce(() => setDebouncedKeyword(keyword), 500, [keyword]);

const onChangedInput = useCallback(
(event: React.ChangeEvent<HTMLInputElement>) => {
setKeyword(event.target.value);
Expand All @@ -34,7 +38,7 @@ const SearchPage: React.FC = () => {
<Text color={Color.MONO_100} id={searchResultsA11yId} typography={Typography.NORMAL20} weight="bold">
検索結果
</Text>
{keyword !== '' && <SearchResult books={books} keyword={keyword} />}
{debouncedKeyword !== '' && <SearchResult books={books} keyword={debouncedKeyword} />}
</Box>
</Box>
);
Expand Down

0 comments on commit eaf4061

Please sign in to comment.