React Hooks Form

React Hooks Form

  • Guides
  • Components
  • Hooks
  • Github

›Hooks

Getting Started

  • Overview
  • Usage

Guides

  • Organizing Your Fields
  • Client-side Validation
  • Server-side Validation
  • Input Components
  • Form Submission
  • Using Hooks

Components

  • <Form />
  • <FormField />

Hooks

  • useFormFieldValue
  • useFormFieldMeta
  • useFormValues
  • useFormMeta
  • useForm

useFormFieldMeta

Use this hook to get a field meta.

Signature

useFormFieldMeta(fieldName[, formName])

Params

NameDescription
fieldNameName of the field
formNameOPTIONAL! Name of the form. You do NOT need to pass this if you use it inside the form context.

Return Value

An object including the following properties:

NameTypeDescription
activeboolWhether the field is focused or not.
visitedboolWhether the field is ever visited.
invalidboolWhether the field is marked as invalid or not.
errormixedField error if it's invalid.

Example

function FieldError({ name }) {
  const { invalid, error, visited } = useFormFieldMeta(name)
  
  if (invalid && visited) {
    return <p>{error}</p>
  }
  
  return null
}
← useFormFieldValueuseFormValues →
  • Signature
  • Params
  • Return Value
  • Example
Docs
Getting StartedGuidesComponentsHooks
Community
Stack Overflow
More
Star
Copyright © 2019 Mehdi Namvar