Skip to main content

RHFDatePicker

RHFDatePicker extends the DatePicker component to let users select a date and can be customized in a similar way.

info

RHFDatePicker uses dayjs as its default adapter. To switch to a different date adapter, please refer the customization guide.

Usage

import { RHFDatePicker, RHFDatePickerProps } from '@nish1896/rhf-mui-components';
<RHFDatePicker
fieldName="dateOfBirth"
register={register}
setValue={setValue}
errorMessage={errors?.dateOfBirth?.message}
/>

Examples

API

RHFDatePickerProps extends DatePickerProps and accepts the following additional props:

NameTypeRequiredDescription
fieldNamestringReact Hook Form requires name as a key for the registration process.
registerUseFormRegisterThe register option yielded on calling the useForm hook.
registerOptionsRegisterOptionsRegister options if using react-hook-form without any validation libraries like yup or Joi.
setValue(name: string, value: unknown, config?: Object) => voidThe setValue option yielded on calling the useForm hook.
onValueChange(newValue: unknown) => voidAn optional callback function which returns the selected date or time value.
showLabelAboveFormFieldbooleanRender form label above the form field in FormLabel component.
formLabelPropsFormLabelPropsFormLabelProps to customise FormLabel 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.