diff --git a/src/components/Header.tsx b/src/components/Header.tsx index b95c6ae..ec908af 100644 --- a/src/components/Header.tsx +++ b/src/components/Header.tsx @@ -21,7 +21,7 @@ export default function Header() { const toggleOpen = () => setIsOpen((prev) => !prev); - const { data } = useNotifications({ size: 10 }); + const { data } = useNotifications({ size: 10 }, isLoggedIn); const hasNotification = (data?.totalCount ?? 0) > 0; const handleLogoClick = () => { diff --git a/src/hooks/useNotification.ts b/src/hooks/useNotification.ts index bd03aff..73e9f56 100644 --- a/src/hooks/useNotification.ts +++ b/src/hooks/useNotification.ts @@ -43,13 +43,17 @@ export const getMyNotifications = async ( * @example * const { data, isLoading } = useNotifications({ size: 10 }); */ -export const useNotifications = (params: NotificationParams) => { +export const useNotifications = ( + params: NotificationParams, + isEnabled: boolean = true, +) => { return useQuery({ queryKey: ['notifications', params], queryFn: async () => { const data = await getMyNotifications(params); return data || { notifications: [], totalCount: 0 }; }, - refetchInterval: 10000, + refetchInterval: isEnabled ? 10000 : false, + enabled: isEnabled, }); };