mirror of
https://github.com/ershisan99/flashcards-example-project.git
synced 2025-12-18 20:59:32 +00:00
in progress
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
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,
|
||||
}}
|
||||
/>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user