-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathform.tsx
25 lines (22 loc) · 874 Bytes
/
form.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { Controller } from 'react-hook-form';
import type { ControllerProps, FieldPath, FieldValues } from 'react-hook-form';
import type { PartialByKeys } from '@/types/utility';
/**
* A wrapper component for controlled inputs
* @description add support for passing render prop as children
* @link https://react-hook-form.com/docs/usecontroller/controller
* @param props
*/
export function FormController<
TFieldValues extends FieldValues = FieldValues,
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
>(
props: (
& PartialByKeys<ControllerProps<TFieldValues, TName>, 'render'>
& { children: ControllerProps<TFieldValues, TName>['render'] }
),
) {
const { children, render, ...otherProps } = props;
return <Controller {...otherProps} render={render || children} />;
}
export { Controller, FormProvider } from 'react-hook-form';