import type { ControllerProps, FieldPath, FieldValues } from './types'; import { useController } from './useController'; /** * Component based on `useController` hook to work with controlled component. * * @remarks * [API](https://react-hook-form.com/docs/usecontroller/controller) • [Demo](https://codesandbox.io/s/react-hook-form-v6-controller-ts-jwyzw) • [Video](https://www.youtube.com/watch?v=N2UNk_UCVyA) * * @param props - the path name to the form field value, and validation rules. * * @returns provide field handler functions, field and form state. * * @example * ```tsx * function App() { * const { control } = useForm({ * defaultValues: { * test: "" * } * }); * * return ( *
* ( * <> * *

{formState.isSubmitted ? "submitted" : ""}

*

{fieldState.isTouched ? "touched" : ""}

* * )} * /> * * ); * } * ``` */ const Controller = < TFieldValues extends FieldValues = FieldValues, TName extends FieldPath = FieldPath, TTransformedValues = TFieldValues, >( props: ControllerProps, ) => props.render(useController(props)); export { Controller };