npm react-hook-form 7.18.0-next.0
Version 7.18.0-next.0

latest releases: 7.53.2, 7.53.1, 7.53.0...
3 years ago

✨ Add support for generic components using FieldPathWithValue (#6562)

type ExpectedType = { test: string };

const Generic = <FormValues extends FieldValues>({
  name,
  control,
}: {
  name: FieldPathWithValue<FormValues, ExpectedType>;
  control: Control<FormValues>;
}) => {
  const {
    field: { value, ...fieldProps },
  } = useController<FormValues, ExpectedType>({
    name,
    control,
    defaultValue: { test: 'value' },
  });

  return <input type="text" value={value.test} {...fieldProps} />;
};

Don't miss a new react-hook-form release

NewReleases is sending notifications on new releases.