mirror of
https://gitlab.massbug.com/massbug/judge4c.git
synced 2025-07-04 15:12:22 +00:00
feat(workspaces): add custom hook to fetch workspaces using React Query
This commit is contained in:
parent
af74979e09
commit
5304524d75
21
src/features/workspaces/api/use-get-workspaces.ts
Normal file
21
src/features/workspaces/api/use-get-workspaces.ts
Normal 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;
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user