@matthew.ngo/reform
Version:
A flexible and powerful React form management library with advanced validation, state observation, and multi-group support
43 lines (42 loc) • 1.38 kB
TypeScript
import { AnyObject } from "yup";
import { ReformReturn } from "../../../types";
import { ReformYupIntegration } from "../types";
/**
* Hook for enhanced Yup integration with Reform
*
* @template T - The type of form data
* @param reform - The Reform hook return value
* @returns Object with enhanced Yup integration utilities
*
* @example
* // Basic usage
* const reform = useReform(config);
* const yupIntegration = useReformYupIntegration(reform);
*
* // Create an enhanced schema with transformers and context
* const enhancedSchema = yupIntegration.createEnhancedSchema(baseSchema);
*
* // Register a transformer for date fields
* useEffect(() => {
* const unregister = yupIntegration.registerTransformer({
* field: 'birthDate',
* transformer: (value) => value instanceof Date ? value : new Date(value),
* transformOn: 'input'
* });
*
* return unregister;
* }, []);
*
* // Validate with context
* const validateGroup = async (groupIndex) => {
* const result = await yupIntegration.validateWithContext(
* reform.getGroupData(groupIndex),
* groupIndex
* );
*
* if (result.error) {
* console.log(result.error);
* }
* };
*/
export declare const useReformYupIntegration: <T extends Record<string, any> & AnyObject>(reform: ReformReturn<T>) => ReformYupIntegration<T>;