diff --git a/packages/console/src/App.tsx b/packages/console/src/App.tsx index aafc69200..a2cd8d797 100644 --- a/packages/console/src/App.tsx +++ b/packages/console/src/App.tsx @@ -35,7 +35,9 @@ const Main = () => { const location = useLocation(); const navigate = useNavigate(); const fetcher = useSwrFetcher(); - const { data } = useSWR('/api/settings'); + + const settingsFetcher = useSwrFetcher(); + const { data } = useSWR('/api/settings', settingsFetcher); useEffect(() => { const theme = data?.adminConsole.appearanceMode ?? defaultTheme; diff --git a/packages/console/src/hooks/use-swr-fetcher.ts b/packages/console/src/hooks/use-swr-fetcher.ts index b924a4dd4..abf9382e3 100644 --- a/packages/console/src/hooks/use-swr-fetcher.ts +++ b/packages/console/src/hooks/use-swr-fetcher.ts @@ -1,4 +1,4 @@ -import { ArbitraryObject, RequestErrorBody } from '@logto/schemas'; +import { RequestErrorBody } from '@logto/schemas'; import { HTTPError } from 'ky'; import { useCallback } from 'react'; import { useTranslation } from 'react-i18next'; @@ -6,14 +6,21 @@ import { BareFetcher } from 'swr'; import useApi, { RequestError } from './use-api'; -const useSwrFetcher = () => { +type withTotalNumber = Array | number>; + +type useSwrFetcherHook = { + (): BareFetcher; + (): BareFetcher>; +}; + +const useSwrFetcher: useSwrFetcherHook = () => { const api = useApi({ hideErrorToast: true }); const { t } = useTranslation(); - const fetcher = useCallback( + const fetcher = useCallback>>( async (resource, init) => { try { const response = await api.get(resource, init); - const data = await response.json(); + const data = await response.json(); if (typeof resource === 'string' && resource.includes('?')) { const parameters = new URLSearchParams(resource.split('?')[1]);