@dev-fastn-ai/react-core
Version:
React hooks and components for integrating Fastn AI connector marketplace into your applications. Built on top of @fastn-ai/core with React Query for optimal performance.
38 lines (37 loc) • 1.44 kB
TypeScript
import type { ConnectorField, SelectOption, FormData } from "@fastn-ai/core";
/**
* Custom hook to manage async select field options with search, pagination, and error handling using React Query.
*
* Benefits of React Query caching:
* - Automatic caching with configurable stale time (5 minutes)
* - Background refetching when data becomes stale
* - Deduplication of requests
* - Optimistic updates
* - Automatic retry on failure
* - Cache invalidation and garbage collection
*
* @param field ConnectorField - The field definition containing optionsSource
* @param context FormData - Optional context data to pass to getOptions and loadMore methods
* @returns { options, loading, loadingMore, hasNext, query, refresh, search, loadMore, error }
*
* @example
* ```tsx
* const { options, loading, loadingMore, hasNext, search, loadMore } = useFieldOptions(field, context);
*
* // Options are automatically cached and shared across components
* // Loading states are handled automatically
* // Pagination is managed with infinite query
* ```
*/
export declare function useFieldOptions(field: ConnectorField, context?: FormData | object): {
options: SelectOption[];
loading: boolean;
loadingMore: boolean;
hasNext: boolean;
query: string;
refresh: () => Promise<void>;
search: (query: string) => void;
loadMore: () => Promise<void>;
totalLoadedOptions: number;
error: string | null;
};