feat(workspaces): add custom hook to fetch workspaces using React Query

This commit is contained in:
ngc2207 2025-02-06 09:21:08 +08:00
parent af74979e09
commit 5304524d75

View File

@ -0,0 +1,21 @@
import { client } from "@/lib/rpc";
import { useQuery } from "@tanstack/react-query";
export const useGetWorkspaces = () => {
const query = useQuery({
queryKey: ["workspaces"],
queryFn: async () => {
const response = await client.api.workspaces.$get();
if (!response.ok) {
throw new Error("Failed to fetch workspaces");
}
const { data } = await response.json();
return data;
},
});
return query;
};