diff --git a/frontend/src/hooks/api/getters/useTags/useTags.ts b/frontend/src/hooks/api/getters/useTags/useTags.ts index 1a1ef26e6e..bb91a5e12d 100644 --- a/frontend/src/hooks/api/getters/useTags/useTags.ts +++ b/frontend/src/hooks/api/getters/useTags/useTags.ts @@ -1,8 +1,9 @@ -import useSWR, { mutate, SWRConfiguration } from 'swr'; +import { mutate, SWRConfiguration } from 'swr'; import { useState, useEffect } from 'react'; import { formatApiPath } from 'utils/formatPath'; import { ITag } from 'interfaces/tags'; import handleErrorResponses from '../httpErrorResponseHandler'; +import { useConditionalSWR } from '../useConditionalSWR/useConditionalSWR'; const useTags = (featureId: string, options: SWRConfiguration = {}) => { const fetcher = async () => { @@ -15,7 +16,13 @@ const useTags = (featureId: string, options: SWRConfiguration = {}) => { const KEY = `api/admin/features/${featureId}/tags`; - const { data, error } = useSWR(KEY, fetcher, options); + const { data, error } = useConditionalSWR<{ tags: ITag[] }>( + Boolean(featureId), + { tags: [] }, + KEY, + fetcher, + options + ); const [loading, setLoading] = useState(!error && !data); const refetch = () => {