UNPKG

mobx-hooks-form

Version:

React form package using mobX, React hooks and context

111 lines (110 loc) 4.31 kB
/// <reference types="lodash" /> import React from 'react'; import * as yup from 'yup'; interface Values { [index: string]: any; } interface Errors { [index: string]: string; } interface Touched { [index: string]: boolean; } interface UseForm { schema: yup.ObjectSchema<Values>; defaultValues?: Values; formName?: string; debug?: boolean; debugMobx?: boolean; DEBOUNCE_MS?: number; } declare class Store { constructor(props: UseForm); debug: boolean; defaultValues: Values; formName: string; DEBOUNCE_MS: number; schema: yup.ObjectSchema<Values>; isTouchedAll: boolean; touched: Touched; submitting: boolean; error: any; setError: (error: any) => void; setSubmitting: (submitting: boolean) => void; values: Values; debouncedValues: Values; getValue: (path: string) => any; getDebouncedValue: (path: string) => any; getValueLength: (path: string) => any; setDebouncedValue: ((path: string, value: any) => void) & import("lodash").Cancelable; pushDebouncedValue: ((path: string, value: any) => void) & import("lodash").Cancelable; removeDebouncedValue: ((path: string, index: number) => void) & import("lodash").Cancelable; pushValue: (path: string, value: any) => void; removeValue: (path: string, index: number) => void; setValue: (path: string) => (value: any) => void; setValues: (values: Values) => void; get validations(): Errors; isRequired: (path: string) => boolean; get isValid(): boolean; reset: () => void; handleSubmit: (submit: (values: Values) => any) => ((e: React.ChangeEvent<HTMLInputElement>) => Promise<void>) & import("mobx").IAction; touch: (path: string) => void; touchAll: () => void; get errors(): Errors; getError: (key: string) => string; getId: (path: string) => string; getField: (path: string) => { path: string; submitting: boolean; readonly value: any; readonly error: string; id: string; setValue: (value: any) => void; onBlur: (() => void) & import("mobx").IAction; onChange: ((e: React.ChangeEvent<HTMLInputElement>) => void) & import("mobx").IAction; onCheckedChange: ((e: React.ChangeEvent<HTMLInputElement>) => void) & import("mobx").IAction; isRequired: boolean; }; getFieldArray: (path: string) => { path: string; readonly error: string; readonly indexes: number[]; id: string; isRequired: boolean; add: ((value?: any) => void) & import("mobx").IAction; remove: ((index: number) => void) & import("mobx").IAction; }; } export declare const useForm: (props: UseForm) => Store; export declare const useFormContext: () => Store; export declare const FormContextProvider: ({ children, formStore, }: { children: React.ReactNode; formStore: Store; }) => JSX.Element; export declare const useField: (path: string) => { path: string; submitting: boolean; readonly value: any; readonly error: string; id: string; setValue: (value: any) => void; onBlur: (() => void) & import("mobx").IAction; onChange: ((e: React.ChangeEvent<HTMLInputElement>) => void) & import("mobx").IAction; onCheckedChange: ((e: React.ChangeEvent<HTMLInputElement>) => void) & import("mobx").IAction; isRequired: boolean; }; export declare const useFieldArray: (path: string) => { path: string; readonly error: string; readonly indexes: number[]; id: string; isRequired: boolean; add: ((value?: any) => void) & import("mobx").IAction; remove: ((index: number) => void) & import("mobx").IAction; }; export declare const useFieldContext: () => {}; export declare const FieldContextProvider: React.FunctionComponent<{ children: (arg0: any) => string | number | boolean | {} | React.ReactElement<any, string | ((props: any) => React.ReactElement<any, string | any | (new (props: any) => React.Component<any, any, any>)> | null) | (new (props: any) => React.Component<any, any, any>)> | React.ReactNodeArray | React.ReactPortal | React.ReactChildren | null | undefined; path: string; }>; export {};