import { Controller, useFormContext } from 'react-hook-form'; import { Switch } from '../form/Switch'; // We control "onChange" & "value" here type FormSwitchProps = Omit, 'onChange'>, 'value'> & { name: string; }; export function FormSwitch(props: FormSwitchProps) { const { name, ...restOfProps } = props; const { control } = useFormContext(); return ( { return ( { onChange(value); return true; }} value={value} /> ); }} name={name} /> ); }