Skip to content
Discussion options

You must be logged in to vote

I've landed on the following solution using Controller:

type Fields = {
  name: string,
  testing: string,
}

export default function Form() {
  const { register, handleSubmit, control, formState: { errors, isSubmitting } } = useForm<Fields>({
    defaultValues: {
      name: "Foo",
      testing: "Bar",
    }
  });

  const onSubmit = (data: any) => console.log(data);

  return (
    <form onSubmit={handleSubmit(onSubmit)} noValidate>

      <FormControl id='name' isInvalid={errors["name"] !== undefined} mb={5} isRequired>
        <FormLabel htmlFor='name'>Name</FormLabel>
        <Input type='text' {...register("name", { required: "This is required." })} />
        {!errors["name"] ? (

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by binajmen
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants