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: 1 comment
-
Hi. Send a sandbox |
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