Function: Form
▸ Const Form(props, ref): Element
This React component renders an HTML form element with an onSubmit handler bound to the current FormProvider context.
Using Form is not a requirement if you prefer to trigger FormState.submit programmatically.
Form offers an onError handler prop to intercept errors thrown from calls it makes to FormState.submit internally.
The following examples are functionally equivalent:
const Example () => { return ( <FormProvider> <Form onError={(error) => { console.log('error'); throw error; }} > ... </Form> </FormProvider> );}const Example () => { const formRef = useRef();
return ( <FormProvider ref={formRef}> <form onSubmit={(event) => { event.preventDefault(); formRef.current?.submit().catch((error) => { console.log('error'); throw error; }); }} > ... </form> </FormProvider> );}Parameters#
| Name | Type |
|---|---|
props | FormProps |
ref | Ref<HTMLFormElement> |
Returns#
Element