From 533ea7dbb9b27794e5d889b938c5c8998fe40a04 Mon Sep 17 00:00:00 2001 From: viown <48097677+viown@users.noreply.github.com> Date: Thu, 6 Mar 2025 18:58:15 +0300 Subject: [PATCH] Disable refetch on window refocus for search suggestions --- .../stable/features/search/api/useSearchSuggestions.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) 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 }); };