exeform
  • Getting Started
  • Motivation
  • How It Works
  • Guides
    • Validation
    • Nested Structures
  • API
    • Form
    • Field
    • <Form />
    • useForm()
    • useField()
    • useCheckboxField()
    • useFieldValue()
    • useFormIsValid()
    • useFormContext()
Powered by GitBook
On this page
  • Import
  • Types
  • Example

Was this helpful?

  1. API

useField()

PrevioususeForm()NextuseCheckboxField()

Last updated 3 years ago

Was this helpful?

This hook subscribes to the part of the form specified in name and returns props for text field, meta information, and helpers.

Import

import { useField } from 'exeform';

Types

See the API for Field .

useField(name: string): Field

Example

For nested values, use name as described .

const TextField = ({ name, ...rest }) => {
  const { field, meta, helpers } = useField(name);
  const error = meta.touched ? meta.error : null;

  return (
    <div>
      <input {...field} {...rest} />
      {error ? <div>{error}</div> : null}
    </div>
  );
};

<TextField name="author.firstName" />
here
here