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

useFormMeta

Use this hook to get the form meta.

Signature

useFormMeta([formName])

Params

NameDescription
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
submittingboolWhether the form is being submitted or not.
submitFailedboolWhether the form submission was failed or not.
submitSucceededboolWhether the form submission was successful or not.
errorobjectAn object including errors if the submission is failed. Both client-side and server-side error will be store here.
resultanyOptional server-side result returned from onSubmit if the submission is successful.

Example

The following example displays form errors:

function FormErrors() {
  const { error, submitFailed } = useFormMeta()

  if (submitFailed) {
    return <p>{error.message}</p>
  }
  
  return null
}

Or suppose you want to add a loading status on the button while the form is being submitted:

function Submit() {
  const { submitting } = useFormMeta()

  return (
    <button type="submit">
      {submitting ? 'Saving...' : 'Save'}
    </button>
  )
}

You can do more and show a success message to the user by the help of submitSucceeded property on the status returned.

← useFormValuesuseForm →
  • Signature
  • Params
  • Return Value
  • Example
Docs
Getting StartedGuidesComponentsHooks
Community
Stack Overflow
More
Star
Copyright © 2019 Mehdi Namvar