Reputation: 31
I'm coding in NextJs and I needed to use 'useForm' but it keeps giving constant errors... "Cannot resolve 'react-hook-form'."Please help.
import React from "react";
import { useForm } from "react-hook-form";
function Presignup() {
const {
register,
handleSubmit,
formState: { errors },
} = useForm;
const submitHandler = (i) => {
{
console.log(i);
}
};
Upvotes: 3
Views: 19986
Reputation: 11
Just add "use client" a the top of the file.
'use client'
import React from "react";
import { useForm } from "react-hook-form";
function Presignup() {
const {
register,
handleSubmit,
formState: { errors },
} = useForm;
const submitHandler = (i) => {
{
console.log(i);
}
};
Upvotes: 1
Reputation: 1
To use React Hook form in next js, you need to create a component and import that component in you page.jsx. In my case I'm using next.js app route and for a signup functionality I've created a component name as Login.jsx(you can name whatever you want) and import that in your login route, for Example import the login.jsx in Login/page.jsx.
Important Note: define the component and page as 'user client' at the top of the file. In mycase I've used 'user client' in my Login.jsx component and Login/page.jsx file.
Upvotes: 0
Reputation: 29
I had the same problem, and i found the solution, try this:
node_modules
npm i
in your terminalIf the same problem continues after following my steps, try reinstalling Node.js
Upvotes: 1
Reputation: 145
maybe am late to answer this get the version of react-hook-form you installed using
npm install react-hook-form
in my case it is version 7.34.2
in your project's root directory... open package.json and into the dependencies object, add
"react-hook-form": "7.34.2"
then run npm install
in teminal on your project's root directory
this worked for me
Upvotes: 7
Reputation: 1048
this should be quite simple, try this solution:
package.json
, see if you already have react-hook-form
library in it.yarn
or npm install
on your directory terminalyarn add react-hook-form
or npm install react-hook-form
Upvotes: 1