@edirect/form-engine
Version:
Achieve form logic reusage with forms expressed in json format.
51 lines (50 loc) • 1.47 kB
TypeScript
import { TChildrenOptions, TFormValues } from './types.js';
import { TField } from '../../core/index.js';
type TProps = {
/**
* The if of the form you want to connect to
*/
id?: string;
/**
* And array of ids of forms you want to connect to
*/
ids?: string[];
/**
* Callback to be called when form validity toggled
* @param data All the available form data
*/
onValid?(data: TFormValues, field: TField): void;
/**
* Callback to be called when the form generates some new data
* @param data All the available form data
*/
onData?(data: TFormValues): void;
/**
* Callback to be called when the form submits
* @param data All the available form data
*/
onSubmit?(data: TFormValues): void;
};
type THookReturn = {
/**
* A function that lets you start the form submission
*/
submitForm(): void;
/**
* You can call this function to get all the updated form data
*
* @param opts Options to configure your form data
*/
formData(opts?: TChildrenOptions): TFormValues;
};
/**
* This hooks lets you connect to your form/s in anywherer in your application. Even if you are outside the <FormProvider />
*
* You can connect to:
* - A specific form
* - Several forms identified by their id's
* - A group of forms
*
*/
declare const useForm: ({ onValid, onData, onSubmit, id, ids }: TProps) => THookReturn;
export default useForm;