Create useVersions.ts
This commit is contained in:
parent
4c26269b68
commit
264d0a20ba
21
frontend/src/hooks/useVersions.ts
Normal file
21
frontend/src/hooks/useVersions.ts
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { fetchVersions } from "@/lib/data";
|
||||||
|
import { AppVersion } from "@/lib/types";
|
||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
|
||||||
|
export function useVersions() {
|
||||||
|
return useQuery<AppVersion[]>({
|
||||||
|
queryKey: ["versions"],
|
||||||
|
queryFn: async () => {
|
||||||
|
const fetchedVersions = await fetchVersions();
|
||||||
|
if (Array.isArray(fetchedVersions)) {
|
||||||
|
return fetchedVersions;
|
||||||
|
}
|
||||||
|
if (fetchedVersions && typeof fetchedVersions === "object") {
|
||||||
|
return [fetchedVersions];
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user