react-antd-admin-panel
Version:
Modern TypeScript-first React admin panel builder with Ant Design 6
72 lines • 1.93 kB
TypeScript
/**
* Options for the useGet hook
*/
export interface UseGetOptions<T> {
/** The URL to fetch */
url: string;
/** Query parameters */
params?: Record<string, any>;
/** Request headers */
headers?: Record<string, string>;
/** Execute immediately on mount (default: true) */
immediate?: boolean;
/** Enable/disable the request (default: true) */
enabled?: boolean;
/** Callback on success */
onSuccess?: (data: T) => void;
/** Callback on error */
onError?: (error: Error) => void;
}
/**
* Return type for the useGet hook
*/
export interface UseGetResult<T> {
/** The fetched data */
data: T | undefined;
/** Loading state */
loading: boolean;
/** Error if request failed */
error: Error | undefined;
/** Execute/re-execute the request */
execute: (overrideParams?: Record<string, any>) => Promise<T | undefined>;
/** Abort the current request */
abort: () => void;
/** Reset state to initial values */
reset: () => void;
}
/**
* useGet - React hook for GET requests
*
* @template T - Response data type
* @param options - Hook options
* @returns Hook result with data, loading, error, and control functions
*
* @example
* ```tsx
* // Basic usage - fetches immediately
* const { data, loading, error } = useGet<User[]>({
* url: '/api/users',
* });
*
* // With parameters
* const { data, loading } = useGet<User[]>({
* url: '/api/users',
* params: { page: 1, limit: 10 },
* });
*
* // Manual execution
* const { data, execute, loading } = useGet<User>({
* url: '/api/users/1',
* immediate: false,
* });
* // Later: await execute();
*
* // Conditional fetch
* const { data } = useGet<User>({
* url: `/api/users/${userId}`,
* enabled: !!userId,
* });
* ```
*/
export declare function useGet<T = any>(options: UseGetOptions<T>): UseGetResult<T>;
//# sourceMappingURL=useGet.d.ts.map