fix get return type
This commit is contained in:
1 parent
a11d551a99
commit
00cf0b6521
3 files changed
+6
-13
No files matched your search
+1
-1
@@ -43,7 +43,7 @@
|
||||
"react-toastify": "^10.0.5",
|
||||
"recharts": "2.15.2",
|
||||
"redux-persist": "6.0.0",
|
||||
"swr": "2.3.6",
|
||||
"swr": "^2.3.6",
|
||||
"vite-plugin-svgr": "^4.2.0",
|
||||
"zod": "4.1.11"
|
||||
},
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import useSWR from "swr";
|
||||
import type { SWRConfiguration } from "swr";
|
||||
import type { AxiosRequestConfig } from "axios";
|
||||
import { get, post, patch, deleteOp } from "@/Utils/ApiClient";
|
||||
import { get } from "@/Utils/ApiClient";
|
||||
|
||||
interface ApiResponse<T> {
|
||||
success: boolean;
|
||||
@@ -9,15 +9,8 @@ interface ApiResponse<T> {
|
||||
data: T;
|
||||
}
|
||||
|
||||
interface UseGetReturn<T> {
|
||||
data: T | undefined;
|
||||
isLoading: boolean;
|
||||
error: Error | undefined;
|
||||
refetch: () => Promise<ApiResponse<T> | undefined>;
|
||||
}
|
||||
|
||||
const fetcher = async <T>(url: string, config?: AxiosRequestConfig) => {
|
||||
const res = await get<T>(url, config);
|
||||
const res = await get<ApiResponse<T>>(url, config);
|
||||
return res.data;
|
||||
};
|
||||
|
||||
@@ -25,7 +18,7 @@ export const useGet = <T>(
|
||||
url: string | null,
|
||||
axiosConfig?: AxiosRequestConfig,
|
||||
swrConfig?: SWRConfiguration
|
||||
): UseGetReturn<T> => {
|
||||
) => {
|
||||
const { data, error, isLoading, mutate } = useSWR<ApiResponse<T>>(
|
||||
url,
|
||||
(url: string) => fetcher<T>(url, axiosConfig),
|
||||
@@ -33,7 +26,7 @@ export const useGet = <T>(
|
||||
);
|
||||
|
||||
return {
|
||||
data: data?.data,
|
||||
data: data?.data ?? null,
|
||||
isLoading,
|
||||
error,
|
||||
refetch: mutate,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { Check } from "@/Types/Check";
|
||||
export type MonitorStatus = "up" | "down" | "initializing";
|
||||
|
||||
export interface IMonitor {
|
||||
export interface Monitor {
|
||||
checks: Check[];
|
||||
createdAt: string;
|
||||
createdBy: string;
|
||||
|
||||
Reference in new issue
Block a user