lesson 2 finished

This commit is contained in:
2023-07-29 17:11:56 +02:00
parent 06afed2826
commit 154cbe60df
12 changed files with 353 additions and 1 deletions

View File

@@ -0,0 +1,36 @@
import { FieldValues, useController, UseControllerProps } from 'react-hook-form'
import { Checkbox, CheckboxProps } from '../../'
export type ControlledCheckboxProps<TFieldValues extends FieldValues> =
UseControllerProps<TFieldValues> & Omit<CheckboxProps, 'onChange' | 'value' | 'id'>
export const ControlledCheckbox = <TFieldValues extends FieldValues>({
name,
rules,
shouldUnregister,
control,
defaultValue,
...checkboxProps
}: ControlledCheckboxProps<TFieldValues>) => {
const {
field: { onChange, value },
} = useController({
name,
rules,
shouldUnregister,
control,
defaultValue,
})
return (
<Checkbox
{...{
onChange,
checked: value,
id: name,
...checkboxProps,
}}
/>
)
}