I don't know why useForm make component to render twice in react+ts+vite project #12865
Unanswered
webdev3614
asked this question in
Q&A
Replies: 3 comments
-
Hi. Send a sandbox |
Beta Was this translation helpful? Give feedback.
0 replies
-
I fixed the issue using react context. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Which version of React are you using? If you're using React 18 or above, React's StrictMode will intentionally trigger renders twice in development mode. This is expected behavior and is not related to React Hook Form. Hope that helps! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I created new project with yarn vite create and I replaced default code with following example code.
import { useForm } from 'react-hook-form';
function App() {
const {
register,
handleSubmit,
formState: { errors },
} = useForm();
console.log("Hello from React Hook Form");
return (
<form onSubmit={handleSubmit((data) => console.log(data))}>
<input {...register('firstName')} />
<input {...register('lastName', { required: true })} />
{errors.lastName &&
Last name is required.
}<input {...register('age', { pattern: /\d+/ })} />
{errors.age &&
Please enter number for age.
});
}
export default App
Beta Was this translation helpful? Give feedback.
All reactions