-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreact-basic.tsx
More file actions
28 lines (23 loc) · 758 Bytes
/
react-basic.tsx
File metadata and controls
28 lines (23 loc) · 758 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { useForm } from 'superform-validator/react';
const schema = {
email: 'required|email',
age: 'integer|minInt(1)',
};
export default function BasicForm() {
const { register, handleSubmit, errors } = useForm(schema, { initialValues: { email: '', age: '' } });
return (
<form onSubmit={handleSubmit((data) => console.log('valid', data), (errs) => console.log('invalid', errs))}>
<label>
Email
<input {...register('email')} />
</label>
{errors.email && <div className="error">{errors.email}</div>}
<label>
Age
<input {...register('age')} />
</label>
{errors.age && <div className="error">{errors.age}</div>}
<button type="submit">Submit</button>
</form>
);
}