diff --git a/src/apps/stable/features/search/api/useSearchSuggestions.ts b/src/apps/stable/features/search/api/useSearchSuggestions.ts index ea6e7b77e0..126783927a 100644 --- a/src/apps/stable/features/search/api/useSearchSuggestions.ts +++ b/src/apps/stable/features/search/api/useSearchSuggestions.ts @@ -7,14 +7,11 @@ import { useQuery } from '@tanstack/react-query'; import { useApi } from 'hooks/useApi'; const fetchGetItems = async ( - api?: Api, - userId?: string, + api: Api, + userId: string, parentId?: string, options?: AxiosRequestConfig ) => { - if (!api) throw new Error('No API instance available'); - if (!userId) throw new Error('No User ID provided'); - const response = await getItemsApi(api).getItems( { userId: userId, @@ -43,7 +40,8 @@ export const useSearchSuggestions = (parentId?: string) => { return useQuery({ queryKey: ['SearchSuggestions', { parentId }], queryFn: ({ signal }) => - fetchGetItems(api, userId, parentId, { signal }), + fetchGetItems(api!, userId!, parentId, { signal }), + refetchOnWindowFocus: false, enabled: !!api && !!userId }); };