import { useField } from 'formik';
import React from 'react';
import { useFormikError } from '../useFormikError';
import { Checkbox, CheckboxProps } from './Checkbox';
export const CheckboxField: React.FC<
  Omit<CheckboxProps, 'error' | 'onChange'>
> = (props) => {
  const error = useFormikError(props.name);
  const [field, , helpers] = useField(props.name);

  return (
    <Checkbox
      {...props}
      value={field.value}
      error={error}
      onChange={helpers.setValue}
    />
  );
};
