Skip to content

react-hook-form 7.35.0

[7.35.0] - 2022-9-10

Added

  • new type FieldPathByValue field path by value generic implementation
function CustomFormComponent<
  TFieldValues extends FieldValues,
  Path extends FieldPathByValue<TFieldValues, Date>,
>({ control, name }: { control: Control<FieldValues>; name: Path }) {
  const { field } = useController({
    control,
    name,
  });
}

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

  return (
    <form>
      <CustomFormComponent control={control} name="foo" /> {/* no error */}
      <CustomFormComponent control={control} name="baz" />{' '}
      {/*  throw an error since baz is string */}
    </form>
  );
}

Changed

  • form context support children prop type
<FormProvider {...methods}>
  <div /> // ✅
  <div /> // ✅
</FormProvider>