import { Checkbox, CheckboxProps } from '@chakra-ui/react'; import { useField, useFormikContext } from 'formik'; import React, { FC } from 'react'; type Overwrite = Pick> & U; export type CheckboxControlProps = Overwrite< CheckboxProps, { value: string | number } > & { name: string; label?: string }; export const CheckboxControl: FC = React.forwardRef( (props: CheckboxControlProps, ref: React.ForwardedRef) => { const { name, label, children, ...rest } = props; const [field, { error, touched }] = useField(name); const { isSubmitting } = useFormikContext(); let isChecked; if (field.value instanceof Array) { isChecked = field.value.includes(props.value) ?? false; } return ( {label} {children} ); } ); export default CheckboxControl;