unregister: (name: string | string[], options) => void
This method allows you to unregister
a single input or an array of inputs. It also provides a second optional argument to keep state after unregistering an input.
Props
The example below shows what to expect when you invoke the unregister
method.
Type | Input Name | Value |
---|---|---|
string | unregister("yourDetails") | {} |
string | unregister("yourDetails.firstName") | { lastName: '' } |
string[] | unregister(["yourDetails.lastName"]) | '' |
Options
Name | Type | Description | Code Examples |
---|---|---|---|
keepDirty | boolean |
| |
keepTouched | boolean |
| |
keepValid | boolean |
| |
keepError | boolean | errors will not be updated. | |
keepValue | boolean | input's current value will not be updated. | |
keepDefaultValue | boolean | input's defaultValue which defined in useForm will be remained. |
Rules
This method will remove input reference and its value which means build-in validation rules will be removed as well.
By
unregister
an input, it will not affect the schema validation.Make sure you unmount that input which has
register
callback or else the input will get registered again.
Examples
Video
The following video explain unregister
API in detail.
Thank you for your support
If you find React Hook Form to be useful in your project, please consider to star and support it.