Everything you need to know about Formedible hooks, components, and utilities. Build powerful, type-safe forms with comprehensive configuration options.
The main hook for creating forms with Formedible. Returns form components and utilities.
function useFormedible<TFormValues>(config: FormedibleConfig<TFormValues>): FormedibleReturn<TFormValues>
interface FormedibleConfig<TFormValues> {// Required: Field definitionsfields: FieldConfig[];// Optional: Zod schema for validationschema?: ZodSchema<TFormValues>;// Optional: TanStack Form optionsformOptions?: FormOptions<TFormValues>;// Optional: Cross-field validationcrossFieldValidation?: CrossFieldValidation[];// Optional: Async validationasyncValidation?: Record<string, AsyncValidationConfig>;// Optional: Form persistencepersistence?: PersistenceConfig;// Optional: Analytics trackinganalytics?: AnalyticsConfig;// Optional: Layout configurationlayout?: LayoutConfig;}
interface FormedibleReturn<TFormValues> {// Main form componentForm: React.ComponentType;// TanStack Form instanceform: FormApi<TFormValues>;// Cross-field validation errorscrossFieldErrors: Record<string, string>;// Async validation statesasyncValidationStates: Record<string, AsyncValidationState>;// Multi-page navigationcurrentPage: number;totalPages: number;goToNextPage: () => void;goToPreviousPage: () => void;goToPage: (page: number) => void;// Persistence utilitiessaveToStorage: (data: Partial<TFormValues>) => void;loadFromStorage: () => SavedFormData<TFormValues> | null;clearStorage: () => void;// Async validation utilitiesvalidateFieldAsync: (fieldName: string, value: any) => Promise<void>;}
Each field in the fields array follows this configuration structure.
interface BaseFieldConfig {// Requiredname: string;type: FieldType;label: string;// Optionaldescription?: string;placeholder?: string;required?: boolean;disabled?: boolean;className?: string;wrapperClassName?: string;// Multi-page supportpage?: number;// Conditional renderingcondition?: (values: any) => boolean;// Help texthelp?: {text: string;tooltip?: string;};// Validationvalidation?: ZodSchema;}
text
- Text inputemail
- Email inputpassword
- Password inputnumber
- Number inputtel
- Phone inputurl
- URL inputtextarea
- Multi-line textselect
- Dropdown selectmultiSelect
- Multi-selectradio
- Radio buttonscheckbox
- Checkboxswitch
- Toggle switchdate
- Date pickerfile
- File uploadslider
- Range sliderrating
- Star ratingcolor
- Color pickerarray
- Dynamic arrayslocation
- Location pickerduration
- Duration inputautocomplete
- Autocompletemasked
- Masked inputphone
- Phone numberConfigure cross-field and async validation for complex form requirements.
interface CrossFieldValidation {fields: string[];validator: (values: Record<string, any>) => string | null;message: string;}
interface AsyncValidationConfig {validator: (value: any) => Promise<string | null>;debounceMs?: number;loadingMessage?: string;}
Configure form data persistence to localStorage or sessionStorage.
interface PersistenceConfig {key: string;storage: 'localStorage' | 'sessionStorage';debounceMs?: number;exclude?: string[];restoreOnMount?: boolean;}
Track form interactions and user behavior for insights.
interface AnalyticsConfig {// Form lifecycle eventsonFormStart?: (timestamp: number) => void;onFormComplete?: (timeSpent: number, formData: any) => void;onFormAbandon?: (completionPercentage: number, context?: any) => void;// Field interaction eventsonFieldFocus?: (fieldName: string, timestamp: number) => void;onFieldBlur?: (fieldName: string, timeSpent: number) => void;onFieldChange?: (fieldName: string, value: any, timestamp: number) => void;onFieldError?: (fieldName: string, errors: string[], timestamp: number) => void;onFieldComplete?: (fieldName: string, isValid: boolean, timeSpent: number) => void;// Multi-page/tab form eventsonPageChange?: (fromPage: number, toPage: number, timeSpent: number, context?: any) => void;onTabChange?: (fromTab: string, toTab: string, timeSpent: number, context?: any) => void;onTabFirstVisit?: (tabId: string, timestamp: number) => void;// Performance trackingonSubmissionPerformance?: (totalTime: number, validationTime: number, processingTime: number) => void;}
All TypeScript types exported by Formedible for type-safe development.
// Main types exported by Formedibleexport type {FormedibleConfig,FormedibleReturn,FieldConfig,BaseFieldConfig,CrossFieldValidation,AsyncValidationConfig,PersistenceConfig,AnalyticsConfig,LayoutConfig,FormTester,FormActions};// Field-specific typesexport type {TextFieldConfig,SelectFieldConfig,DateFieldConfig,FileFieldConfig,LocationFieldConfig,DurationFieldConfig,AutocompleteFieldConfig,MaskedInputFieldConfig};
Now that you know the API, start building powerful forms with Formedible. Create beautiful, type-safe forms with comprehensive validation and features.