Zuletzt aktiv 1734220241

Änderung 392dc1eefe9115b83d2d69666999019b2c770ce6

React-Hook-Form-2.jsx Orginalformat
1import { useForm } from 'react-hook-form';
2
3function App() {
4 const {
5 register,
6 handleSubmit,
7 formState: { errors },
8 } = useForm();
9
10 return (
11 <form onSubmit={handleSubmit((data) => console.log(data))}>
12 <input {...register('firstName')} />
13 <input {...register('lastName', { required: true })} />
14 {errors.lastName && <p>Last name is required.</p>}
15 <input {...register('age', { pattern: /\d+/ })} />
16 {errors.age && <p>Please enter number for age.</p>}
17 <input type="submit" />
18 </form>
19 );
20}