use-form
use-form hook options and returned form object
Source
Package
License
Examples
This page is the useForm reference. Complete forms that combine several features,
with full code, are available on a separate page:
Usage
The useForm hook returns a form object with values, errors, validation and submission handlers.
Installation and a walkthrough of the example below are on the Get started page:
Options
All options are optional. Options are read on every render, you can pass values that depend on props or state.
mode–uncontrolled(default) orcontrolled, see Form modesinitialValues– initial form values, define the shape and type of the form, see Form valuesinitialErrors,initialTouched,initialDirty– initial errors and field statusvalidate– rules object, function or schema, see Form validationvalidateInputOnChange,validateInputOnBlur– validate fields on change or blur,trueor an array of field pathsclearInputErrorOnChange– clear field error when its value changes,trueby defaultvalidateDebounce– debounce in ms for async validation triggered on change or blurresolveValidationError– converts an error thrown by an async rule to an error messagetransformValues– transforms values before they are passed to the submit handler, see Form submissiononSubmitPreventDefault–always(default),neverorvalidation-failedonValuesChange– called with new and previous values on every change, see Watching valuescascadeUpdates– notify nested field watchers whenform.setFieldValueor an input sets a parent path,falseby defaultenhanceGetInputProps– adds props to the object returned byform.getInputProps, see getInputPropstouchTrigger–change(default) orfocus, see Form statusname– form name for form actions
Form object
All examples below use the following form:
Values
Inputs
Watchers
List items
Validation
Errors
Submission
Touched and dirty
Types
UseFormReturnType, TransformedValues, FormErrors, FormPath and useForm generics are described
on the use-form types page.