gitscope
← marzneshin / v0.3.1 / dashboard/src/features/nodes/services/node.query.ts
https://dev.kronoz.win/r/marzneshin.git
dashboard/src/features/nodes/services/node.query.ts · TypeScript
Blame Raw
 1import { useQuery } from "@tanstack/react-query";
 2import { fetch } from "@marzneshin/utils";
 3import type { NodeType } from "../types";
 4
 5export async function fetchNode({
 6    queryKey,
 7}: { queryKey: [string, number] }): Promise<NodeType> {
 8    return await fetch(`/nodes/${queryKey[1]}`).then(result => result);
 9}
10
11export const NodeQueryFetchKey = "nodes";
12
13export const useNodeQuery = ({ nodeId }: { nodeId: number }) => {
14    return useQuery({
15        queryKey: [NodeQueryFetchKey, nodeId],
16        queryFn: fetchNode,
17        initialData: null,
18    });
19};