Morrys Repositories

Morrys Repositories

  • Docs
  • GitHub

›API Reference

Home

  • Build forms in React with Relay

Getting Started

  • relay-forms
  • react-relay-forms
  • relay-forms-nodeps

Simple Example

  • Simple Example

API Reference

  • useFormSubmit
  • useFormSetValue
  • useFormState
  • useFormValue

useFormState

This hook allows you to find out the state of the form

input parameters

No input parameters

return

export type FormStateReturn = {
    errors: ReadonlyArray<
        | {
              readonly id: string;
              readonly key: string;
              readonly error: string | null;
          }
        | null
        | undefined
    >;
    isValidating: boolean;
    isSubmitting: boolean;
};

isValid: is true if all fields of the form have been validated without errors

errors: the values of all fields that contain errors are returned

isValidating: it is used to define when the form is being validated

isSubmitting: it is used to define when the form is being submitted

example

export const HAVE_ERRORS = 'have errors';

export const Errors: React.FC<any> = () => {
    const { errors, isSubmitting, isValidating } = useFormState();
    return (
        <>
            <div>{errors ? HAVE_ERRORS : ''}</div>;
            <div>{'' + isSubmitting}</div>;
            <div>{'' + isValidating}</div>;
        </>
    );
};

Last updated on 22/10/2020 by morrys
← useFormSetValueuseFormValue →
Morrys Repositories
Docs
about relay-forms
Community
User Showcase
More
GitHubStar
Follow @m0rrys
Facebook Open Source
Copyright © 2023 Lorenzo Di Giacomo