extended-dynamic-forms
Version:
Extended React JSON Schema Form (RJSF) v6 with custom components, widgets, templates, layouts, and form events
70 lines (68 loc) • 2.47 kB
TypeScript
import { DataSourceConfig, ChoiceOption, LoadingState, ErrorState } from '../ChoiceWidget.types';
import { DataSourceEventCallbacks, DataSourceMetrics } from '../providers/DataSourceProvider';
/**
* Hook return type for useDataSource
*/
export interface UseDataSourceReturn {
/** Available choice options */
options: ChoiceOption[];
/** Loading state information */
loading: LoadingState;
/** Error state information */
error: ErrorState;
/** Refetch data from the source (bypasses cache) */
refetch: () => Promise<void>;
/** Refresh data (uses cache if available) */
refresh: () => Promise<void>;
/** Update the data source configuration */
updateConfig: (config: DataSourceConfig) => void;
/** Performance metrics for monitoring */
metrics: DataSourceMetrics;
/** Whether the cached data is stale */
isStale: boolean;
}
/**
* Custom React hook for managing data source lifecycle
*
* Features:
* - Manages loading, success, and error states
* - Handles provider switching and configuration changes
* - Implements caching coordination with providers
* - Provides refetch and refresh capabilities
* - Prevents race conditions with request cancellation
* - Includes performance monitoring
* - Ensures proper cleanup on unmount
*
* @param config - Data source configuration
* @param eventCallbacks - Optional event callbacks for monitoring
* @returns Data source state and control functions
*
* @example
* ```tsx
* const { options, loading, error, refetch } = useDataSource({
* type: 'api',
* url: '/api/options',
* responseMapper: { type: 'simple' }
* });
* ```
*/
export declare function useDataSource(config: DataSourceConfig, eventCallbacks?: DataSourceEventCallbacks): UseDataSourceReturn;
/**
* Helper hook for managing data source with automatic error retry
*
* @param config - Data source configuration
* @param options - Hook options
* @returns Data source state with automatic retry
*/
export declare function useDataSourceWithRetry(config: DataSourceConfig, options?: {
maxRetries?: number;
retryDelayMs?: number;
onRetry?: (attempt: number, error: Error) => void;
}): UseDataSourceReturn;
/**
* Helper hook for managing multiple data sources
*
* @param configs - Array of data source configurations
* @returns Array of data source states
*/
export declare function useMultipleDataSources(configs: DataSourceConfig[]): UseDataSourceReturn[];