Skip to content
On this page

unregister

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.

  • Type
interface Options {
  keepDirty?: boolean
  keepError?: boolean
  keepValue?: boolean
}

type UnregisterFn = (name: string, options?: Options)
  • Usage'
const { unregister } = useForm()

unregister('name', {
  keepDirty: true,
  keepError: true,
  keepValue: true
})
  • Playground

Try it on Playground

KeepDirty

if set to true, isDirty and dirtyFields will be remained during this action.

  • Type
const keepDirty: boolean = false
  • Usage
<input :="register('test', { keepDirty: true })" />

keepError

if set to true, errors will not be updated.

  • Type
const keepError: boolean = false
  • Usage
<input :="register('test', { keepError: true })" />

keepValue

if set to true, field's current value will not be updated.

  • Type
const keepValue: boolean = false
  • Usage
<input :="register('test', { keepValue: true })" />