rehance-forms
Version:
Form utilities for React
27 lines (26 loc) • 902 B
TypeScript
import * as React from "react";
import { ScopeContext } from "./ScopeContext";
export declare type FieldMutations = {
update(nextState: Partial<FieldState>): void;
};
export declare type WithFieldProps<ChildProps> = ChildProps & {
name: string;
field: FieldState & FieldMutations;
scope: ScopeContext;
};
export declare type CustomFieldProps<ChildProps> = ChildProps & {
name: string;
keepChangesOnUnmount?: boolean;
};
export declare type FieldState = {
value: any;
error: string | null;
touched: boolean;
changed: boolean;
};
export declare function bindAsField<ChildProps extends object = {}>(Component: React.ComponentType<WithFieldProps<ChildProps>>): React.ForwardRefExoticComponent<React.PropsWithoutRef<{
children?: React.ReactNode;
} & ChildProps & {
name: string;
keepChangesOnUnmount?: boolean | undefined;
}> & React.RefAttributes<any>>;