mirror of
https://github.com/ershisan99/flashcards-example-project.git
synced 2025-12-16 20:59:27 +00:00
37 lines
722 B
TypeScript
37 lines
722 B
TypeScript
import { FieldValues, useController, UseControllerProps } from 'react-hook-form'
|
|
|
|
import { Checkbox, CheckboxProps } from '@/components'
|
|
|
|
type Props<T extends FieldValues> = UseControllerProps<T> &
|
|
Omit<CheckboxProps, 'checked' | 'onValueChange' | 'id'>
|
|
|
|
export const ControlledCheckbox = <T extends FieldValues>({
|
|
name,
|
|
rules,
|
|
shouldUnregister,
|
|
control,
|
|
defaultValue,
|
|
...checkboxProps
|
|
}: Props<T>) => {
|
|
const {
|
|
field: { onChange, value },
|
|
} = useController({
|
|
name,
|
|
rules,
|
|
shouldUnregister,
|
|
control,
|
|
defaultValue,
|
|
})
|
|
|
|
return (
|
|
<Checkbox
|
|
{...{
|
|
onValueChange: onChange,
|
|
checked: value,
|
|
id: name,
|
|
...checkboxProps,
|
|
}}
|
|
/>
|
|
)
|
|
}
|