Skip to content
Discussion options

You must be logged in to vote

I've opened a pull request that creates a type for using like this. check #8837. On the description it's also an example of usage:

import {
  FieldPathByValue,
  FieldValues,
  Control,
  useController,
  useForm
} from "react-hook-form";

// this component uses a date value
function SomeCustomFormComponent<
    TFieldValues extends FieldValues,
    TPath extends FieldPathByValue<TFieldValues, Date>
>({
    control,
    name
}: {
    control: Control<TFieldValues>,
    name: TPath
}) {
    const { field } = useController({
      control,
      name,
    });

    // rest of components rules
}

function ExampleOfUsage () {
    const {control} = useForm<{
        foo: Date;
        baz: string;

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@QzCurious
Comment options

@carvalheiro
Comment options

@Spacerat
Comment options

@paulleonartcalvo
Comment options

@MarceloPrado
Comment options

Answer selected by jpapini
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
6 participants