@pagamio/frontend-commons-lib
Version:
Pagamio library for Frontend reusable components like the form engine and table container
47 lines (46 loc) • 2.42 kB
TypeScript
/**
* @fileoverview SWR integration for the API client
*/
import { type Key, type SWRConfiguration, type SWRResponse } from 'swr';
import type { ApiErrorResponse, RequestConfig, SpringBootResponse } from './types';
/**
* Main SWR hook that automatically inherits auth config
* @template ResponseData - Type of the expected response data
* @template ErrorData - Type of the error response (defaults to ApiErrorResponse)
*/
export declare function useApiSWR<ResponseData, ErrorData = ApiErrorResponse>(endpoint: Key, config?: RequestConfig & SWRConfiguration<ResponseData, ErrorData>): SWRResponse<ResponseData, ErrorData>;
/**
* Paginated SWR hook that inherits auth config
* @template ItemType - Type of items in the paginated response
* @template ResponseType - Type of the full response (defaults to SpringBootResponse)
*/
export declare function usePaginatedApiSWR<ItemType, ResponseType extends {
content: ItemType[];
} = SpringBootResponse<ItemType>>(endpoint: Key, config?: RequestConfig & SWRConfiguration<ResponseType>): SWRResponse<ResponseType>;
/**
* Mutation hook that inherits auth config
* @template ResponseData - Type of the expected response data
*/
export declare function useApiMutation<ResponseData>(): {
post: (endpoint: string, data?: unknown, config?: RequestConfig) => Promise<ResponseData>;
put: (endpoint: string, data?: unknown, config?: RequestConfig) => Promise<ResponseData>;
patch: (endpoint: string, data?: unknown, config?: RequestConfig) => Promise<ResponseData>;
delete: (endpoint: string, config?: RequestConfig) => Promise<ResponseData>;
};
/**
* Combined SWR and mutation hook
* @template ResponseData - Type of the expected response data
*/
export declare function useApiSWRWithMutation<ResponseData>(endpoint: Key, config?: RequestConfig & SWRConfiguration<ResponseData>): {
mutate: {
post: (endpoint: string, data?: unknown, config?: RequestConfig) => Promise<ResponseData>;
put: (endpoint: string, data?: unknown, config?: RequestConfig) => Promise<ResponseData>;
patch: (endpoint: string, data?: unknown, config?: RequestConfig) => Promise<ResponseData>;
delete: (endpoint: string, config?: RequestConfig) => Promise<ResponseData>;
};
refresh: () => Promise<any>;
data: ResponseData | undefined;
error: ApiErrorResponse | undefined;
isValidating: boolean;
isLoading: boolean;
};