Form
For building a form for collecting information from the user.
This form component is a wrapper around the react-hook-form
library. We’ll also use zod
to validate the form.
Anatomy
Components
UiForm
Contains all the parts of a form.
This component is a wrapper of the react-hook-form
library FormProvider
component.
Example
Props
Name | Type | Description |
---|---|---|
...props | object | Require all the useUiForm methods |
UiFormField
The wrapper for a form field.
This component is a wrapper of the react-hook-form
library Controller
component.
Example
Props
Name | Type | Description |
---|---|---|
name | string | Name of the field |
control | Control | control object is from invoking useUiForm |
render | Function | A function that returns a React element and provides the ability to attach events and value into the component |
UiFormItem
The wrapper for a form field. It handles id of the field.
Example
Props
Name | Type | Description |
---|---|---|
noContainer | ?boolean | Whether to wrap the field inside a <div> element |
UiFormLabel
A label element for the field which is automatically wired when nested inside a UiFormItem
component.
Example
UiFormControl
A control element which is automatically wired when nested inside a UiFormField
component.
Example
UiFormDescription
A description about the field.
Example
UiFormMessage
Display the validation message when the value doesn’t match the schema of the given field.
Example
Hooks
useUiForm
Wrapper around the useForm
hook of the react-hook-form
library.