TTMT.ManageWebGUI/src/hooks/useQueryData.ts

26 lines
494 B
TypeScript
Raw Normal View History

2025-11-19 14:55:14 +07:00
import { useQuery } from "@tanstack/react-query";
import axios from "axios";
2025-08-11 23:21:36 +07:00
type QueryDataOptions<T> = {
2025-11-19 14:55:14 +07:00
queryKey: string[];
url: string;
params?: Record<string, any>;
select?: (data: any) => T;
enabled?: boolean;
};
2025-08-11 23:21:36 +07:00
export function useQueryData<T = any>({
queryKey,
url,
params,
select,
enabled = true,
}: QueryDataOptions<T>) {
return useQuery<T>({
queryKey,
queryFn: () => axios.get(url, { params }).then((res) => res.data),
select,
enabled,
2025-11-19 14:55:14 +07:00
});
2025-08-11 23:21:36 +07:00
}