Skip to content

API Reference

Complete API documentation for Vue Hook Form.

Composables

ComposableDescription
useFormMain form management composable
useControllerController for custom input components
useFormStateSubscribe to form state changes
useWatchWatch field value changes

Context

FunctionDescription
FormProviderProvide form context to child components
useFormContextAccess form context in child components

Types

TypeDescription
UseFormOptionsOptions for useForm
UseFormReturnReturn value of useForm
FormStateForm state object
FieldArrayField array manager
PathType-safe field paths

Quick Reference

useForm

typescript
const {
  register, // Register an input
  handleSubmit, // Handle form submission
  formState, // Reactive form state
  fields, // Get field array manager
  setValue, // Set field value
  getValue, // Get field value
  getValues, // Get all values
  reset, // Reset form
  trigger, // Trigger validation
  watch, // Watch field values
  setError, // Set field error
  clearErrors, // Clear errors
} = useForm({
  schema, // Zod schema (required)
  defaultValues, // Initial values
  mode, // Validation mode
  disabled, // Disable form
  shouldUseNativeValidation,
})

register

typescript
// Uncontrolled (default)
const bindings = register('fieldName')
// Returns: { name, ref, onChange, onBlur }

// Controlled
const { value, ...bindings } = register('fieldName', { controlled: true })
// Returns: { value: Ref, name, onChange, onBlur }

formState

typescript
formState.value.errors // { [field]: string }
formState.value.isDirty // boolean
formState.value.isValid // boolean
formState.value.isSubmitting // boolean
formState.value.isSubmitted // boolean
formState.value.isSubmitSuccessful // boolean
formState.value.submitCount // number
formState.value.touchedFields // Set<string>
formState.value.dirtyFields // Set<string>

fields

typescript
const arrayManager = fields('items')

arrayManager.value // Array of { key, index, remove() }
arrayManager.append(value)
arrayManager.prepend(value)
arrayManager.insert(index, value)
arrayManager.remove(index)
arrayManager.swap(indexA, indexB)
arrayManager.move(from, to)
arrayManager.replace(values)

Released under the MIT License.