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
  • useCheckboxField
  • field.checked
  • Example

Was this helpful?

  1. API

useCheckboxField()

PrevioususeField()NextuseFieldValue()

Last updated 3 years ago

Was this helpful?

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

Import

import { useCheckboxField } from 'exeform';

Types

The returned value is almost identical to . The only difference is that the checked field is present instead of value.

useCheckboxField

useCheckboxField(name: string): CheckboxField

field.checked

boolean

Example

For nested values, use name as described .

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

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

<Checkbox name="activated" />
Field
here