Skip to content

Commit

Permalink
fix: 같은 검색결과 반환값을 캐싱하도록 queryKey 수정(#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
rbgksqkr committed Jun 18, 2024
1 parent 9f50ac5 commit 4c5934d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/hooks/useSearchAutoCompleteQuery.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { getSearchResult } from '@/apis/docs';
import { useQuery } from '@tanstack/react-query';

export const useSearchAutoCompleteQuery = (searchInput: string) => {
export const useSearchAutoCompleteQuery = (searchKeyword: string) => {
const { data, isLoading } = useQuery({
queryKey: ['autoComplete', searchInput],
queryFn: () => getSearchResult(searchInput),
queryKey: ['search', searchKeyword],
queryFn: () => getSearchResult(searchKeyword),
select: (search) => {
if (search.kind === 'searchResultList') {
const titleList: string[] = [];
search.data.forEach((data) => {
if (data.title.includes(searchInput)) titleList.push(data.title);
else if (data.content.includes(searchInput)) titleList.push(data.title);
if (data.title.includes(searchKeyword)) titleList.push(data.title);
else if (data.content.includes(searchKeyword)) titleList.push(data.title);
});
return titleList;
} else if (search.kind === 'searchResult') {
return [search.data.title];
}
},
staleTime: 30 * 1000,
staleTime: 60 * 1000,
});
return { data, isLoading };
};

0 comments on commit 4c5934d

Please sign in to comment.