Skip to main content
Version: 2.0

RHFCheckbox

The RHFCheckbox component renders a checkbox, allowing users to toggle options on or off, such as subscribing to newsletters. It extends the Checkbox component from MUI, accepting most of its props and offering similar customization options.

Usage

import RHFCheckbox, { RHFCheckboxProps } from '@nish1896/rhf-mui-components/mui/checkbox';
<RHFCheckbox
fieldName="agreeTnC"
control={control}
label="Agree to Terms & Conditions"
errorMessage={errors?.agreeTnC?.message}
/>

Examples

API

RHFCheckboxProps extends CheckboxProps and accepts the following additional props:

NameTypeRequiredDescription
fieldNamestringReact Hook Form requires name as a key for the registration process. This is a required prop for all components.
controlUseFormControlThe control option yielded on calling the useForm hook.
registerOptionsRegisterOptionsRegister options for validation if using react-hook-form without any validation libraries like yup or Joi.
onValueChange(isChecked: boolean, e: ChangeEvent) => voidAn optional callback function which returns the state of the checkbox.
labelReactNodeThe text to render in FormLabel component. By default, the value of fieldName such as firstName will be transformed to display "First Name".
formControlLabelPropsFormControlLabelPropsFormControlLabelProps to customise FormControlLabel component for a field. Multiple fields can be configured using the ConfigProvider component.
helperTextReactNodeThe content to display within the FormHelperText component below the field. If the field validation fails, this content will be overridden by the corresponding error message.
errorMessageReactNodeError message to be shown for a field in FormHelperText component.
hideErrorMessagebooleanA flag to prevent replacement of helper text of a field by the error message when the validation is triggered.
formHelperTextPropsFormHelperTextPropsFormHelperTextProps to customise FormHelperText component for a field. Multiple fields can be configured using the ConfigProvider component.