https://dev.kronoz.win/r/marzneshin.git
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};