Refactor useAccounts hook to use React Query instead of SWR; remove SWR dependency from package.json and package-lock.json

This commit is contained in:
mykonos-ibiza 2025-08-11 19:39:44 +05:30
parent a01202f622
commit 0731ffb872
3 changed files with 7 additions and 25 deletions

View File

@ -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",

View File

@ -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",

View File

@ -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<GetAccountsResponse>) => {
const supabaseClient = createClient();
return useSWR<GetAccountsResponse>(
async () => {
const { data: { user } } = await supabaseClient.auth.getUser();
return user ? ['accounts', user.id] : null;
},
async () => {
return useQuery<GetAccountsResponse>({
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,
});
};