Zuletzt aktiv 1734220241

knox hat die Gist bearbeitet 1734220241. Zu Änderung gehen

1 file changed, 20 insertions

React-Hook-Form-2.jsx(Datei erstellt)

@@ -0,0 +1,20 @@
1 + import { useForm } from 'react-hook-form';
2 +
3 + function 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 + }
Neuer Älter