lynx-form-x
Version:
LynxFormX is a lightweight and intuitive form library built for the Lynx framework for mobile development. It streamlines form management by automatically binding fields, handling validation, and providing easy-to-use hooks for custom field manipulation—a
35 lines (34 loc) • 826 B
TypeScript
export declare enum ActionType {
SET_VALUE = 0,
SET_ERROR = 1,
SET_TOUCHED = 2,
SET_IS_SUBMITTING = 3,
RESET = 4
}
export type Errors<T> = Partial<Record<keyof T, string>>;
export type FormState<T> = {
values: T;
errors: Partial<Errors<T>>;
touched: Partial<Record<keyof T, boolean>>;
isSubmitting: boolean;
};
export type Action<T> = {
type: ActionType.SET_VALUE;
field: keyof T;
value: any;
} | {
type: ActionType.SET_ERROR;
field: keyof T;
error: string;
} | {
type: ActionType.SET_TOUCHED;
field: keyof T;
touched: boolean;
} | {
type: ActionType.RESET;
initialValues: T;
} | {
type: ActionType.SET_IS_SUBMITTING;
isSubmitting: boolean;
};
export declare function formReducer<T>(state: FormState<T>, action: Action<T>): FormState<T>;