Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React-Hook-Form useForm is not a function

I am using NextJS 14 and React Hook Form and I keep running in this error.

error

I used the guide from the official docs and nothing worked.

I have tried uninstall react hook form and reinstalling it, also attempted to delete package-lock.json and node_modules.

export default function Home() {
  const {
    register,
    formState: { errors },
  } = useForm<FormData>({
    resolver: zodResolver(UserSchema), // Apply the zodResolver
  });

  return (
      <form onSubmit={() => {}}>
        <div className="grid col-auto">
          <FormField
            type="email"
            placeholder="Email"
            name="email"
            register={register}
            error={errors.email}
          />
          <button type="submit">
            Submit email
          </button>
        </div>
      </form>
  );
};
like image 855
Antx Avatar asked Jun 12 '26 21:06

Antx


2 Answers

Add "use client" at the very top of your component.

"use client"

export default function Home() {
  const {
    register,
    formState: { errors },
  } = useForm<FormData>({
    resolver: zodResolver(UserSchema), // Apply the zodResolver
  });

  return (
      <form onSubmit={() => {}}>
        <div className="grid col-auto">
          <FormField
            type="email"
            placeholder="Email"
            name="email"
            register={register}
            error={errors.email}
          />
          <button type="submit">
            Submit email
          </button>
        </div>
      </form>
  );
};
like image 155
X8inez Avatar answered Jun 15 '26 12:06

X8inez


In NextJS 14, when using useForm from React Hook Form, the component must be marked as a client component. To ensure this, add "use client"; at the top of your file. This directive ensures that the component is rendered on the client side, which is necessary for React Hook Form to function correctly.

like image 26
Md Mahfuz RP Avatar answered Jun 15 '26 12:06

Md Mahfuz RP