Closed StringKe closed 9 months ago
import { Checkbox as $Checkbox } from '@mantine/core'; import { useController } from 'react-hook-form'; import type { CheckboxProps as $CheckboxProps } from '@mantine/core'; import type { FieldValues, UseControllerProps } from 'react-hook-form'; import { CheckboxGroup } from './CheckBoxGroup/CheckBoxGroup'; export type CheckboxProps<T extends FieldValues> = UseControllerProps<T> & Omit<$CheckboxProps, 'checked' | 'defaultValue'>; export const Checkbox = <T extends FieldValues>({ name, control, defaultValue, rules, shouldUnregister, onChange, ...props }: CheckboxProps<T>) => { const { field: { value, onChange: fieldOnChange, ...field }, fieldState, } = useController<T>({ name, control, defaultValue, rules, shouldUnregister, }); return ( <$Checkbox error={fieldState.error?.message} value={value} checked={value} onChange={(e) => { fieldOnChange(e); onChange?.(e); }} {...field} {...props} /> ); }; Checkbox.Group = CheckboxGroup; Checkbox.Item = $Checkbox;
error log:
[23-10-18 04:05:20] error: Cannot support type: (79) Checkbox [23-10-18 04:05:20] error: Error: Cannot support type: (79) Checkbox
full project: https://github.com/aranlucas/react-hook-form-mantine
Stale issue message
error log:
full project: https://github.com/aranlucas/react-hook-form-mantine