---
name: CheckBoxField
menu: Components
---

import PropsTable from 'website-src/components/PropsTable'
import { livePreviewStyle } from '../helpers/constants'
import CheckBoxField from './CheckBoxField'
import cactusTheme from '@repay/cactus-theme'
import { LiveProvider, LiveEditor, LiveError, LivePreview } from 'react-live'

# CheckBoxField

The `CheckBoxField` is a combination of `CheckBox` and `Label`, along with some accessibility features that are taken care of for you.

### Try it out

export const code = `<CheckBoxField name="checkboxfield" label="Is Checked"/>`

<LiveProvider code={code} scope={{ CheckBoxField }}>
  <LiveEditor style={livePreviewStyle} />
  <LiveError />
  <LivePreview />
</LiveProvider>

## Best practices

- Use meaningful labels for each `CheckBoxField` so that they are accessible.
- If you don't provide an ID, a unique ID will be generated for you.

## Basic usage

```jsx
import React, { useState } from 'react'
import { Button, CheckBoxField } from '@repay/cactus-web'

export default function Form() {
  const [values, setValues] = useState({ checkboxfield: false })
  const handleChange = useCallback(
    (e) => {
      setValues(state => ({ ...state, [e.target.name]: e.target.checked }))
    },
    [setValues]
  )
  const onSubmit = useCallback(
    event => {
      event.preventDefault()
      const data = { ...values }
      // send data to api
    },
    [values]
  )

  return (
    <form onSubmit={onSubmit}>
      <CheckBoxField
        name="checkboxfield"
        label="Is Checked"
        onChange={handleChange}
        value={values.checkboxfield}
      />
      <Button type="submit" variant="action">
        Submit
      </Button>
    </form>
  )
}
```

## Properties

<PropsTable of={CheckBoxField} />
