Skip to main content

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';
<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.
controlUseFormControlThe control option yielded on calling the useForm hook.
onValueChange(e: ChangeEvent) => voidAn optional callback function which returns the state of the checkbox from e.target.checked value
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.
helperTextReactNodeOptional helperText to render under RHFSelect or RHFNativeSelect field.
errorMessageReactNodeError message to be shown for a field in FormHelperText component.
hideErrorMessagebooleanPrevent replacing of form HelperText by error message during validation trigger.
formHelperTextPropsFormHelperTextPropsFormHelperTextProps to customise FormHelperText component for a field. Multiple fields can be configured using the ConfigProvider component.