From 0731ffb87249c935559430d505ad6a34920588b4 Mon Sep 17 00:00:00 2001 From: mykonos-ibiza <222371740+mykonos-ibiza@users.noreply.github.com> Date: Mon, 11 Aug 2025 19:39:44 +0530 Subject: [PATCH] Refactor useAccounts hook to use React Query instead of SWR; remove SWR dependency from package.json and package-lock.json --- frontend/package-lock.json | 14 -------------- frontend/package.json | 1 - frontend/src/hooks/use-accounts.ts | 17 +++++++---------- 3 files changed, 7 insertions(+), 25 deletions(-) diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 2ba60bcf..2176eb98 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -103,7 +103,6 @@ "remark-gfm": "^4.0.1", "server-only": "^0.0.1", "sonner": "^2.0.3", - "swr": "^2.2.5", "tailwind-merge": "^3.0.2", "tailwind-scrollbar": "^4.0.2", "tailwind-scrollbar-hide": "^2.0.0", @@ -14097,19 +14096,6 @@ "node": ">=12.0.0" } }, - "node_modules/swr": { - "version": "2.3.3", - "resolved": "https://registry.npmjs.org/swr/-/swr-2.3.3.tgz", - "integrity": "sha512-dshNvs3ExOqtZ6kJBaAsabhPdHyeY4P2cKwRCniDVifBMoG/SVI7tfLWqPXriVspf2Rg4tPzXJTnwaihIeFw2A==", - "license": "MIT", - "dependencies": { - "dequal": "^2.0.3", - "use-sync-external-store": "^1.4.0" - }, - "peerDependencies": { - "react": "^16.11.0 || ^17.0.0 || ^18.0.0 || ^19.0.0" - } - }, "node_modules/tailwind-merge": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/tailwind-merge/-/tailwind-merge-3.3.0.tgz", diff --git a/frontend/package.json b/frontend/package.json index c09f4b43..732782e4 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -107,7 +107,6 @@ "remark-gfm": "^4.0.1", "server-only": "^0.0.1", "sonner": "^2.0.3", - "swr": "^2.2.5", "tailwind-merge": "^3.0.2", "tailwind-scrollbar": "^4.0.2", "tailwind-scrollbar-hide": "^2.0.0", diff --git a/frontend/src/hooks/use-accounts.ts b/frontend/src/hooks/use-accounts.ts index 59e2bd2f..0cfb34a7 100644 --- a/frontend/src/hooks/use-accounts.ts +++ b/frontend/src/hooks/use-accounts.ts @@ -1,16 +1,13 @@ -import useSWR, { SWRConfiguration } from 'swr'; +import { useQuery, UseQueryOptions } from '@tanstack/react-query'; import { createClient } from '@/lib/supabase/client'; import { GetAccountsResponse } from '@usebasejump/shared'; -export const useAccounts = (options?: SWRConfiguration) => { +export const useAccounts = (options?: UseQueryOptions) => { const supabaseClient = createClient(); - return useSWR( - async () => { - const { data: { user } } = await supabaseClient.auth.getUser(); - return user ? ['accounts', user.id] : null; - }, - async () => { + return useQuery({ + queryKey: ['accounts'], + queryFn: async () => { const { data, error } = await supabaseClient.rpc('get_accounts'); if (error) { @@ -19,6 +16,6 @@ export const useAccounts = (options?: SWRConfiguration) => { return data; }, - options, - ); + ...options, + }); };